How do I create a reference to a Widget within another widget blueprint?
Hello! First of all: I have recently gotten into blueprint scripting which means I am not very experienced, so please have that in mind =) I will try to make my self as clear as possible!
Okey, here is the deal
A while ago, I started creating a sort of cookie-clicker clone on Scratch.mit.edu as a way of learning to script, but I abandoned it because the quality was too bad. However, I decided that I wanted to try and create it using blueprints in Unreal 4. I started using widgets as it makes it easy to create a setup of buttons and images which is just what I need for the project.
Here is the two widgets I have made:
The one above is my main widget! Whenever i click the earth, a variable within the "Main Widget blueprint" adds "1" to itself, and the number is displayed under the earth (as you see)
When clicking the "Shop" button down in the left corner, another widget appears:
This is the shop widget! When I click one of the two items in the middle, it adds to floats within the "Shop Widget Blueprint"
However: I have problems with reopening the Shop after closing it!
The first thing I tried to do, was for it to remove the widget itself from the game, but that lead to the Float-values being erased, which I really didn't want, so I made it so that when I clicked "Exit Shop", the widget just moves out of view! ... but then it is seamlessly impossible to get the "Shop" button in the "Main widget" to make the shop appear again without having to completely recreate the widget!
...because I cant create a reference to the "Shop widget" in the "Main widget Blueprint"
Here is also a picture of how I spawn the widgets when the game start! I choose this setup because my float-values kept getting deleted when simply "re-creating" widgets
I have tried many different methods of making this system work, but I always run into the Float values being reset, or being unable to creating a reference to the widgets...
What am I doing wrong? Is there a much simpler way to do this? ...And should I really use widgets do do this?... I don't know! (Don't be afraid of making me feel like an idiot, that is probably what I need right now) ;) ;)
asked May 20 '16 at 11:06 PM in Blueprint Scripting
You not aware that you making reference, what do you think outputs from "Create Widget" that blue pin? Refrence of just created widget, set it varable before adding to viewport and reuse as much as you want. On creation use "IsValid" on that that varable to see if widget been already created if not, create, if yes dont create and just use what is in varable. Same goes with actors, Spawn Actor outputs actor reference so you can control it, keep it in varable insted of using heavy "Get All Actors of Class" all the time
answered May 21 '16 at 02:19 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here