Hi, I am starting to learn UE4 and Blueprints, but seem to be stuck at a pretty primitive level.
What I am trying to do is essentially to create a class blueprint to hold some data, which I can persist in GameInstance and serialise in a save game.
As a simple test I have created a Class Blueprint called ‘PlayerData’ derived from Object, which has two string variables - ‘PlayerName’ and ‘PlayerClass’.
I have created a MyGameInstance derived from GameInstance and given it an object variable SomePlayerData of type ‘PlayerData’, then set the Game Instance type on my test level to ‘MyGameInstance’.
I now want to be able to access my PlayerData from the test Level Blueprint, but can’t figure out how to actually instantiate it.
On Begin Play I get a reference to the game instance, cast it to MyGameInstance and set it as a variable ‘TheGameInstance’ in the level blueprint. I then try to access TheGameInstance->SomePlayerData so that I can set some dummy values for PlayerName and PlayerClass, but it is not a valid object… presumably because it has never been created. I cannot find any way to instantiate the PlayerData class so that I can store it in TheGameInstance, though.
The result when I run the level is ‘NO PLAYER DATA’.
If I were writing code I would add something like SomePlayerData = new PlayerData() to the MyGameInstance constructor, but I can’t see any equivalent in Blueprints.
I assume that I am conceptualising something wrongly, but going through a multitude of tutorials hasn’t really helped me to understand what I am not understanding.
The basic idea is to use the blueprint ‘PlayerData’ to encapsulate some common data between the game instance and the save game, so that serialising it is easier. If I set up MyGameInstance with variables of built in types (i.e. string variables ‘PlayerName’ and ‘PlayerClass’) I can set them, but then I have to replicate the same variables in MySaveGame and copy each value individually to serialise them, which sounds like a maintenance nightmare.
If non-actor class blueprints can’t be instantiated there wouldn’t seem to be much point in having them, so I assume there is some way to do so?