x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

alt text

This is the blueprint for it

alt text

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!

Product Version: UE 4.19
Tags:
widget.png (23.4 kB)
blueprint1.png (188.5 kB)
more ▼

asked Jun 05 '18 at 08:38 PM in Blueprint Scripting

avatar image

alefaso
12 2 1 4

avatar image AZTECCO Jun 06 '18 at 12:50 PM

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

avatar image alefaso Jun 13 '18 at 11:57 PM

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. alt text

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jun 06 '18 at 08:57 PM

avatar image

ZazarLaLiche
218 2 3 7

avatar image alefaso Jun 13 '18 at 11:40 PM

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

avatar image Nebula Games Inc Jun 14 '18 at 12:47 AM

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.

avatar image ZazarLaLiche Jun 14 '18 at 06:19 AM

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.

avatar image alefaso Jun 21 '18 at 03:52 AM

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.

avatar image Nebula Games Inc Jun 21 '18 at 04:30 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question