Casting playername object unkown?

I’m a bit confused when loading variables from game instance such as username. I don’t know what to plug in for the object. plugging get game instance node doesn’t work for mine. And I’m a bit confused, would someone kind enough to help me out?

If your save game object is in the game instance, you would have to gain access to it:

Cast it to whatever name your custom GameInstance is. The same goes for simple variables.

Open SaveTheGame blueprint and in the very upper right corner check what class you are inheriting from. Does is say GameInstance?

For mine, whenever I plugin “Get game instance” to Cast to node it shows this. "Warning Save The Game does not inherit from Game instance cast to Save The game would always fail.

It’s parent class is set to Save game.

And that’s why you cannot do it - Save game is not the same as GameInstance.

GameInstance is an object that is created when you start the game and is destroyed when you quit the game. You technically do not have to use it but it’s more than suitable to store data.

To create one, right click in the content browser, select Blueprint Class, find game instance in the list and select it. This will create a custom, extended GameInstance for you to use. Make sure to give it a meaningful name, like MyGameInstance, for example :wink:

Now that you have it, you need to tell the engine to use it. In the Project SettingsMaps and Modes, at the very bottom:

You should be able to store variables that are globally accessible there. GetGameInstanceCastToMyGameInstanceGetYourData.

Hope it helps a bit.

I’ve followed your instructions. And did my best of my knowledge in UE4 blueprints. But it seems to not work.
I’ve casted the variables to mygameinstance.

Here it I can make casting node work now. But the username isn’t displaying in the main menu.

You have 2 objects GameInstance and SaveGame. SaveGame stores data you can load/unload from disc. GameInstance stores the SaveGame so it does not perish when you transition between levels.

Create a SaveGame blueprint - you’ve done it already, you called it SaveTheGame, it has the Username and Password variables. Next, create an instance of that object in your GameInstance and promote it to a variable:

From now on you access the data like so:

May i ask how custom event for SaveGame is triggered? Because in other widget I cannot call the custom event.

You create the save game object when you want to save the game. It is up to you where or when you do it. The Custom Event CreateSaveGame sits in the GameInstance - you can see it the upper-right corner of my screenshot. You can GetGameInstance->Cast it->Call the Event. This will create a SaveGame, you can then access that save game, set any variables inside and save it to a slot.

When calling event; would the target be savethegame Reference and target it to password / username?

I do not understand what you are trying to do anymore. I’m assuming you want to read/write data from a SaveGameObject and you want that SaveGameObject reside in the GameInstance.

The screenshot above shows the Event that creates a SaveGameObject inside GameInstance. The screenshot below shows how to access that SaveGameObject in order to read/write data from/to it.

I’m trying to call event in my usercreation menu; which casts to mygameinstance, then get event saveGame; but it requires an target node to be plugged. I cannot plug in my username target to the target node for SaveGame event.

Even though I’ve connected the target node from mygameinstance to SaveGame event my username doesn’t showup?

Even though I’ve connected the target
node from mygameinstance to SaveGame
event my username doesn’t showup?

Once connected, the SaveGameObject will be created. You can then access its data. You also need to assign SaveGameObject’s password to the widget’s variable that stores is.

The way I try to do it was set the textbox and make it a variable then bind it to my username variable; which gets the username data from mygameinstance but seems to not work. In my previous method I it worked; when I just sent the username variable from login menu to main menu.