I have a widget that is the HUD for when the player clicks on an object, but before that, I have a widget that is the HUD for when the game starts. In the GameStartHUD widget, I created a text box where the player would create their username and OnNTextCommitted would set the username to a string variable named UsernameSaved that I set to public.
Now I want to get the UsernameSaved variable to also be the binding for the objectclickedHUD widget text box to display it later on but it won’t let me access it and will only let me create a new binding.
So basically I want the player to create a username in one widget and then for the next widget to get that variable (which is the binding for the first widget) and display it on screen at a later time (I want to use the same binding for both widgets)
GameStartWidget Text Box with content binding:
The binding for GameStart Widget Text Box:
ObjectWidget Text Box with no binding (but want binding of other widget):
I want that MyUsername to display on the black box after I press ENTER:
If there’s not a way to do that, then how would I do it in the new binding, this is what I got so far but I’m stuck…:
Hi ItsTeaTime,
You’ll need to get a reference to the UsernameSaved variable stored on your GameStartHUD widget in order to bind your username display text to it. You can accomplish this using the ‘Get All Widgets of Class’ node, then casting it to the correct class.
Perhaps a cleaner way to handle this is to move your UsernameSaved variable to your GameMode blueprint. You can easily grab a reference to that blueprint using the ‘Get Game Mode’ node, then cast it to the correct type and access your UsernameSaved variable that way. Let me know if anything is unclear and I’ll elaborate.
Best,
Cody
The second paragraph I didn’t really undesrstand since I didn’t even know there was such a thing as a GameMode blueprint! I only know of switching gamemodes and level blueprints.
I tried to do what you said in the first paragraph but I’m stuck, I don’t know what to make the target of the Username Saved node:
The ‘Found Widgets’ pin on ‘Get All Widgets of Class’ is going to be a list of all GameStartHUD widgets that currently exist. You can drag off of that and attach a ‘Get’ node to grab a specific instance. If you know that only one exists, you can get the first element in the array (element 0) and access the variable from there.
The only downside with this approach is that if you remove your GameStartHUD widget, you’ll lose the variable holding your username! You may want to consider attaching the UsernameSaved variable to a different blueprint, one that you know will always exist. You could create a custom GameMode blueprint and store things there (more information on this [here][2].) If you’re planning to implement multiplayer, you may want to look into adding it as a PlayerState variable and accessing it from there.
Thank you for the answer and advice, I will surely look up PlayerState variables and such because I am going to implement multiplayer eventually!
Also, this is just me being a curious cat, but do you think it would be practical / a good idea to allow bindings to be shared in multiple widgets, sort of like a new feature for the engine? Or would it be too confusing?