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"

How to carry variables through levels with game instance.

Hey so I am trying to make a game where you need to collect items. The problem that is happening though is I don't know how to carry the variables through levels. I tried doing this with a game instance by having those variables in the game instance and making an event tick to constantly set the game instance variables to the characters variables. Then when you open a new level the characters variables get set to the game instances. Any ideas why this is not working?alt text

Product Version: UE 4.19
1.png (109.1 kB)
2.png (105.3 kB)
more ▼

asked Jun 10 '18 at 04:13 PM in Blueprint Scripting

avatar image

48 1 4 7

avatar image ThompsonN13 Jun 10 '18 at 05:16 PM

you have the game instance set to be the one used in the project settings right?

also i wouldnt set the variables on tick it would probably be much better to initialize the variables on begin play. if you have the variables being set on tick then you may have a hard time updating them and its not a efficient way to get this done.

avatar image mightyenigma Jun 10 '18 at 05:33 PM

Also just set them in the game instance whenever you set them elsewhere. Maybe even just only store them in game instance and nowhere else if youre not doing multiplayer so you dont have to copy the values around

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

1 answer: sort voted first

You're doing it backwards. You want "game instance" to SET "player" variables after you switch levels not the other way around. Before you leave a level you want "player" to SET "game instance" variables.

So you play level 1...collect 500 gold then you want to travel to level 2. What you do is cast to game instance FROM player and SET "Game Instance" gold = player gold.

Then you open level 2. Player gold = 0 because it isn't carried over from level to level BUT "game instance" gold = 500. So now you want to SET "player" gold TO the "game instance" value and continue on.

This is usually best accomplished with functions. So just before "end level" call a function that sets game instance variables to current player values.

Then on level start, you can have the level BP call a function that sets "player variables" to game instance values. Problem solved!

more ▼

answered Jun 10 '18 at 05:28 PM

avatar image

Nebula Games Inc
5.4k 28 9 15

(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