1. 创建和设置
创建继承自 GameInstance 的C++类
? ?
头文件里加上 UCLASS(BlueprintType, Blueprintable)
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "MyGameInstance.generated.h"
/**
*
*/
UCLASS(BlueprintType, Blueprintable)
class EXERCISE_API UMyGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float health = 10.0f;
};
然后打开Project Settings -> Engine -> General Settings -> Default Class下的 Game Singleton Class, 选择你刚创建好的类
?
? ? ?
2. 在蓝图里使用
右键
? ??
? ??
3. 多个单例
很简单,直接再创建一个类继承第一步创建的MyGameInstance就可以了
? ?
? ?
?
|