Store "Pawn" variable on GameInstance from a wiget

Greetings community, this site has been a huge encyclopedy but now i seek information that doesn’t seem to be already ansered.

I am working on a battle RPG map (say, oldschool fnal fantasy style) and i am on the phase of spawning the characters, both enemy and player’s.
I have created “pawn” type variables on the gameinstance, i intend to store on those variables the enemy types that will be spawn on the map, depending wich area the player is crossing.

For the time being i created a simple widget to allow myself to set those “pawn” variables manually so i can continue wit other aspects of the game.

243224-widget.png

This is the blueprint for it

Explained: when you click the button, it cast to the game instance (also gets game instance for reference), set’s a bolean to true (this is a mark for wether the button is clicked, for other process) casts the game instance again (maybe unnecessary or redundand but there it is) and checks if the content of a combobox is equal to “cave needle” if it is, then proceeds to get al actors from class “ave needle”, gets a copy, and stores the pawn to the “Eslot1” variable that is stored on the gameinstance.

I’ve beent esting and debuging, so far the boolean that is stored on the gameinstance is set to true with no problem, therefore i believe the “cast to game instance” is not the issue, also the branch condition in wich the content of the combobox and the string are equal ecause when debuging the nodes “bright” as they are continuing ot the next one, but whenever i call the conent of the variable “eslot1” it returns “None” as if the variable is empty.

Any guiding on this issue is very appreciated, and thanks for reading!

Hello! You are casting a gameInstance to a playerState, try to stay a print node from cast failed and see

I’m not sure I understand, do you spawn any CaveNeedle before calling this code ?

And also, yes casting twice is not useful here, just use the output of your first cast, or even store it in a variable for future use as casts can be expensive.

Hello there! No, the map itself has no “CaveNeedle” spawn at the time the code is called

Hola AZTECCO thanks for your answer!
I added a printstring to see if the cast failed, it didn’t show up when the bleprint is put to run (by pressing a button on the GUI).

The “playerslots” class is not a playerState is a GameInstance class i created and named “playerslots” as shown bellow.

244204-playerslotsclass.png

Well that is your issue! How can you expect to store a reference to the “Cave Needle” if you haven’t yet spawned one? The “Get All Actors of Class” node searches your entire level for any actors of the specified class and returns all the actors it identifies into an array. So if you haven’t spawned any “Cave Needle” actors yet, the array is empty, the “get” is null, the reference is invalid. Spawn one in before you call this and you’re good.

Yes, that was the point of my question :). You need to spawn them at some point using a spawn node, or place them in the level, depending on your design. Then you get a reference to it and do your stuff with it.

Thank you guys Zazar And Nebula, given that the map has no “characters” when loaded, how could i spawn any character from a blueprin class on my project?

Sorry for the late reply i have been away from home.

Use the “spawn actor from class” node. And you can even save the output pin from that node as a variable which is a reference to the spawned actor solving your initial problem