I started to learn to use the unreal engine 4 but I still have some questions. One question is, where is the best entry point to setting up gameplay classes for storing data and starting for example simulating behaviors.
I mean the real game state data like quest progress, player information with inventory or status like amount of money or current status of a simulated world or AI behavior but more in a global way.
Where is the best entry point to initialize these global classes? Maybe also load data from a savegame and store it in some data models. So all data which are not directly realted to an actor.
Would be nice if someone can give me some tips or hints.
Thanks.
Hi,
yeah I saw all these tutorials, but my question is still open. I also looked into a Slate Tutorial which is using a Singleton class to store styles.
There the neccessary singleton object will be created in the module class where the StartupModule and ShutdownModule functions are overriden.
So now I see the following possibilities to start creating game related classes, which are not directly Actors like data or world simulation classes:
creating on Module class startup
creating in GameMode class
creating in GameState class
only player specific data creating in PlayerState class
But how accessing the data? Singletons is a solution, but I am not sure if this is the best way?
It’s complicated because we’re unable to rely on BeginPlay of any basic classes (States, Controllers, Pawns and etc.). So i’m using Controller’s begin play with lazy load (load on first call) of the others. The reason of using so complicated way is not constant init order in UE4.
I think the intended way to deal with run-time data that is not directly tied to a level or game mode is the [FONT=Courier New]UGameInstance](UGameInstance | Unreal Engine 5.2 Documentation) class, at least according to this post.
However the problem with that class is that it doesn’t really help with data that needs to be accessible in the editor, e.g., a data table that is used to populate stats of characters as you place them into the level. As far as I can tell the most reliable way to deal with this problem is to use custom game engine classes that store the persistent data. This seems to be confirmed by the answers in this thread, although I’d be happy to learn of a simpler alternative.
If you want to see an example that uses this method to configure actors in the editor using data from data tables you can look at my C++ implementation of the “Game-Ready AI” stream at https://gitlab.com/mhoelzl/GameReadyAiCpp. The custom engine classes are in [FONT=Courier New]GameReadyAiCpp/AIS_GameEngine., [FONT=Courier New]GameReadyAiEditor//Engines/AIS_EditorEngine.* and [FONT=Courier New]GameReadyAiEditor//Engines/AIS_UnrealEdEngine..