I’m attempting to create a UI that counts and displays the number of enemies in the level. It stands to reason this logic would need to be in some class that transcends any particular actor. After some digging, I came across GameMode and GameState.
It’s my understanding one of the biggest differences is that GameMode only exists on the server. Since each client’s hud would need to track this info, I decided GameState was a better choice.
There’s very little in the custom game state right now:
UCLASS()
class MECH_API AMechGameState : public AGameStateBase
{
GENERATED_BODY()
public:
virtual void BeginPlay() override;
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere)
int enemiesInLevel = 0;
};
Here in the hud widget’s event graph, I’ve promoted the GameState to a variable so I can access it for UI.
However, I’m unable to access its members from inside this binding.
It’s also my understanding that GameState classes are created automatically as a singleton when the game launches. However, I came across this category in Project Settings and it occurred to me that perhaps I need to manually set the project to my newly-created state class before it will work.
However, the option to change any of these values is disabled, save for GameMode. After much more reading, I’m getting the distinct impression that I need to set a custom GameMode before setting a custom GameState (although no one has explicitly said this outright).
Is that true? If so, why? If not, is there another flaw in my approach?