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"

How can i keep a variable's value consistent throughout all the levels?

I have a coin variable for my player, and say i collect 5 coins and then die or exit to the main menu or exit the game, i want the coin value to add everything up so i can spend them in a store for items.

SKYPE: cjsavage56 (red shirt)

EMAIL: cjsavage56@gmail.com

Product Version: UE 4.14
Tags:
more ▼

asked Feb 09 '17 at 06:55 PM in Blueprint Scripting

avatar image

Fabulous_hotdog
34 4 7 14

avatar image NymKappa Feb 09 '17 at 07:38 PM

1 ........

avatar image NymKappa Feb 09 '17 at 07:38 PM

2 ........

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

2 answers: sort voted first

Check out the GameInstance Blueprint class.

It is a Bp where you can store and change variables that then will carried over from level to level.

It works like a regular Blueprint, but when you set your created Instance as the GameInstance i will then not be reset from level to level, and as such will be where you store your money variable, (and also where you store your bought items when you return to the world).

more ▼

answered Feb 09 '17 at 09:04 PM

avatar image

Fjordhoj
147 6 6 10

avatar image NymKappa Feb 09 '17 at 09:05 PM

Won't work for "or exit the game" though :/

avatar image Fabulous_hotdog Feb 09 '17 at 09:07 PM

Thank you.

avatar image Fjordhoj Feb 09 '17 at 09:17 PM

No, if you need the variable stored outside of the game, you would than take the GameInstance variable, and place it in a save game object (there are also some good documentation on that if you are unceartian of this).

Then when the game is opened, you load the variable before the main game is started, and place it back into theGameInstance.

With these executions, you will now have the possibility to store your variable between levels/menus and between program starts :-)

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

3 ........seconds to google it and find https://docs.unrealengine.com/latest/INT/Gameplay/SaveGame/

more ▼

answered Feb 09 '17 at 07:39 PM

avatar image

NymKappa
687 30 20 50

avatar image Fabulous_hotdog Feb 09 '17 at 08:16 PM

Are you autistic? That is not what i am asking, i am asking specific.

I know how to save a game.

avatar image NymKappa Feb 09 '17 at 08:20 PM

Then why did you accept the answer... autist ?

EDIT: Actually since you asked for "exit the game", my first answer is the good one. If you don't understand it, I can't help you.

(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