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"

Using a bool in GameInstance to spawn an actor

So I am trying to spawn an actor in my battle game mode, depending on whether or not he was in my previous level before the transition. I am using a GameInstance that contains a bool which gets set to true when the actor is spawned in the previous level, however this does not seem to be working for me. I can't just spawn the actor in without checking if it was spawned previously as I am going to be implementing Stats for each individual fighter. I am totally stuck here as I can't really think of another way to do this. The BP below is in my battle scene level BP.![alt text Any help is much appreciated!

Product Version: UE 4.19
spawnactor.png (197.8 kB)
more ▼

asked May 07 '18 at 06:57 PM in Blueprint Scripting

avatar image

15 2 2 6

avatar image Nebula Games Inc May 07 '18 at 07:01 PM

Screenshot missing

avatar image Icepaw May 07 '18 at 07:07 PM

woops, should be sorted now

avatar image Nebula Games Inc May 07 '18 at 07:08 PM

Where are you setting this boolean? Screen shot that too please. Also what exactly is the issue? It doesn't spawn? The boolean never gets set? The boolean isn't read properly?

avatar image Icepaw May 07 '18 at 07:10 PM

alt text I'm setting it inside the actor BP (in this case it's the ThirdPersonCharacterBP) and the issue is in my level that I want the actor to spawn, it isn't spawning at all. for testing I have just set the bool to always on, so I'm assuming it's not being read correctly?

setbool.png (65.0 kB)
avatar image Nebula Games Inc May 07 '18 at 07:13 PM

Seems simple enough, so must be a small error somewhere. Unfortunately that means more screen shots. Need to see the entire chain of logic from start to finish. So, how this actor is spawned initially, how this function is called etc. Need the whole flow. Everything seems good from here but is this function actually called? Do you load a new level and spawn again? What exactly is all the back end of this.

avatar image Icepaw May 07 '18 at 07:22 PM

So the actor is just placed in the scene here: alt text The bool function is being set on eventplay here(in the 3rdpersoncharBP): alt text I am trying to Spawn a different BP actor in another level here: alt text and in this new level BP I have the actor spawn BP function set here (titled spawn players): alt text

avatar image Nebula Games Inc May 07 '18 at 07:39 PM

Ok this is more complex than you made it out to be initially. Are you loading this from a save game? Because if so there is a whole other area for error right there. Also, gameinstance persists between levels so unless you truly need to "save" like power off the computer and come back to the same spot this is not necessary, game instance will handle persistence between levels. If you are using this bool from a save game then I would need screen shots of how the game is saved and loaded up. That is most likely the error, I see that issue all the time due to improper saving of data.

avatar image Icepaw May 07 '18 at 07:47 PM

No I'm not using a save game, I just have the function in the same chain as my savegame function because I needed to use the BeginPlay event, is this bad practice? I don't think it is what is causing the issue though as for now I have just set the bool I am using to true (Which is stored inside a GameInstance and is set to editable)alt text

gameinstance.png (385.9 kB)
avatar image Icepaw May 07 '18 at 08:50 PM

Okay a little update, I put a print string on the cast failed node and it seems that it is always failing for some reason

avatar image Nebula Games Inc May 07 '18 at 09:01 PM

Check the right side world settings panel for the level you are in. Are you using the correct game mode and game instance you are casting to?

avatar image Icepaw May 07 '18 at 09:11 PM

alt text alt text Well I'm overriding the game mode, but the cast is the correct one. The same goes for the game instance unless GetGameInstance can be changed somehow? alt text alt text

gamemode.png (72.2 kB)
gameovveride.png (124.2 kB)
asdfadf.png (98.8 kB)
names.png (7.0 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Okay so it turns out that I am a complete idiot haha, I didn't realise I had to set the the game instance that I made in the project settings, sorry for troubling you and thanks for your help

more ▼

answered May 07 '18 at 09:26 PM

avatar image

15 2 2 6

avatar image Nebula Games Inc May 07 '18 at 09:31 PM

No worries, that's what I figured when game instance doesn't cast really only 1 reason that happens... not using the right game instance haha anyway glad you figured it out

(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