在运行时创建和更改游戏状态
Create and change game State in runtime
我正在努力解决 title.For 中提到的问题,现在我在构造函数中设置默认值,然后我想用我的函数更改它,但是它似乎不起作用。
void AMyGameModeBase::SwapGameState(AGameStateBase* GameStateVariable)
{
GameStateClass = GameStateVariable->StaticClass();
}
我怎样才能正确地做到这一点?好的解释会很棒:)
编辑:
所以这是我的全部代码:
MyGameModeBase.h
#pragma once
#include "GameFramework/GameMode.h"
#include "MyGameModeBase.generated.h"
/**
*
*/
UCLASS()
class PROJECT_API AMyGameModeBase : public AGameMode
{
GENERATED_BODY()
public:
AMyGameModeBase();
UFUNCTION(BlueprintCallable, Category="GameState")
void SwapGameState(AGameStateBase* GameStateVariable);
};
MyGameModeBase.cpp
#include "Project.h"
#include "MyGameModeBase.h"
AMyGameModeBase::AMyGameModeBase()
{
GameStateClass = AGameStateBase::StaticClass();
}
void AMyGameModeBase::SwapGameState(AGameStateBase* GameStateVariable)
{
GameStateClass = GameStateVariable->StaticClass();
}
我现在正在做的是:
1.Open 游戏模式蓝图
2.Drag 从 Event 开始播放并调用 SwapGameState
3.I正在创建引用 MyGameState 的变量。
4.Then 我正在使用节点 "GetGameState" 获得的打印字符串名称进行打印,发现它没有改变。
我想要实现的是:
1.CreateGameState 在运行时
2.Set 它也在运行时使用默认游戏状态。
StaticClass 函数是一个静态函数,您可以这样调用MyStateClass::StaticClass()
你要的是这个
void AMyGameModeBase::SwapGameState(AGameStateBase* GameStateVariable)
{
GameStateClass = GameStateVariable->GetClass();
}
我正在努力解决 title.For 中提到的问题,现在我在构造函数中设置默认值,然后我想用我的函数更改它,但是它似乎不起作用。
void AMyGameModeBase::SwapGameState(AGameStateBase* GameStateVariable)
{
GameStateClass = GameStateVariable->StaticClass();
}
我怎样才能正确地做到这一点?好的解释会很棒:)
编辑:
所以这是我的全部代码: MyGameModeBase.h
#pragma once
#include "GameFramework/GameMode.h"
#include "MyGameModeBase.generated.h"
/**
*
*/
UCLASS()
class PROJECT_API AMyGameModeBase : public AGameMode
{
GENERATED_BODY()
public:
AMyGameModeBase();
UFUNCTION(BlueprintCallable, Category="GameState")
void SwapGameState(AGameStateBase* GameStateVariable);
};
MyGameModeBase.cpp
#include "Project.h"
#include "MyGameModeBase.h"
AMyGameModeBase::AMyGameModeBase()
{
GameStateClass = AGameStateBase::StaticClass();
}
void AMyGameModeBase::SwapGameState(AGameStateBase* GameStateVariable)
{
GameStateClass = GameStateVariable->StaticClass();
}
我现在正在做的是: 1.Open 游戏模式蓝图 2.Drag 从 Event 开始播放并调用 SwapGameState 3.I正在创建引用 MyGameState 的变量。 4.Then 我正在使用节点 "GetGameState" 获得的打印字符串名称进行打印,发现它没有改变。
我想要实现的是: 1.CreateGameState 在运行时 2.Set 它也在运行时使用默认游戏状态。
StaticClass 函数是一个静态函数,您可以这样调用MyStateClass::StaticClass()
你要的是这个
void AMyGameModeBase::SwapGameState(AGameStateBase* GameStateVariable)
{
GameStateClass = GameStateVariable->GetClass();
}