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"

Make widget button set variable inside level blueprint?

My widget has buttons and all of them would set a variable to a new integer value. I have tried using a reference of the widget and a get node branched off of the reference, but the value never commits to what it is set at. The widget is in a separate level, so the value is set, then the user is transported into the main level w/ level blueprint that inhibits the set value from the referenced widget to the get int value of the variable. Anyone know what I am doing wrong?

Product Version: UE 4.9
Tags:
more ▼

asked Dec 16 '15 at 02:20 AM in Blueprint Scripting

avatar image

nmm131
170 48 49 60

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

1 answer: sort voted first

don't store long term variables in the level blueprint. if you want to transfer variables to another level, store the variable in a gameinstance or savegame.

try not to use the level blueprint unless you want to do something unique, which is only done in that level, and does not affect anything in any other level. even then, its usually a better idea to use actors placed in the level rather than putting stuff in the level blueprint.

more ▼

answered Dec 16 '15 at 03:32 AM

avatar image

ScottSpadea
9.6k 320 205 450

avatar image nmm131 Dec 16 '15 at 03:46 AM

The variable must be set in another level bp, in a separate level there is just a widget and its buttons which when pushed have to set a variable to some integer. This variable never works though inside the main level blueprint.

I can't have the widget in any other level, that's why I'm trying to get the variable into another level's blueprint, b/c there is nothing except a widget in that level.

avatar image ScottSpadea Dec 16 '15 at 03:50 AM

you don't need to put the variable inside a level blueprint. the widget can store the variable inside a custom gameinstance, and in the other level, you can read the variable from your gameinstance.

in the widget, use GetGameInstance, cast to your CustomGameInstance, and set the variable. in the other level, you can GetGameInstance and get the variable.

avatar image nmm131 Dec 16 '15 at 04:07 AM

GetGameInstance --> CastToGameInstance gives me an error 'Return Value' is already a 'Game Instance' you don't need CastToGameInstance. alt text

bbb.png (77.3 kB)
avatar image ScottSpadea Dec 16 '15 at 04:39 AM

first, you should make a new blueprint based on GameInstance, called something like MyGameInstance. you can add any variables you want to keep between levels to that blueprint's list of variables. then, under Edit > ProjectSettings > Maps and Modes > at the very bottom, you can set the Game Instance Class to your custom MyGameInstance.

then when you use GetGameInstance inside a blueprint, you can cast to MyGameInstance, and set or get its variables.

avatar image nmm131 Dec 16 '15 at 04:20 PM

alt text alt text

I click the button to assign variable W to an integer but in the level blueprint the get W returns no value

I tried this with a blueprint actor just as a billboard to store the W value and the same thing occurred.

2.png (114.4 kB)
1.png (146.5 kB)
avatar image ScottSpadea Dec 16 '15 at 04:40 PM

that should work. did you set Edit > ProjectSettings > Maps and Modes >GameInstanceClass to MyGameInstance?

avatar image nmm131 Dec 16 '15 at 07:29 PM

I had set it to GameInstance instead of MyGameInstance. This allowed my variable to be set! Thank you very much, I thought it might have been a bug.

avatar image RuBa1987 Dec 16 '15 at 12:50 PM

I second this. While there are always dozens of ways of doing a thing especially when dealing with code you want to strive for the most correct way to do it. Otherwise things get messy and complicated and introduce instability.

While it may be frustrating to rework your architecture to accommodate what @Omnicypher is suggesting is the best option from my understand of the issue.

(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