I have multiple menus that I need to access the outer canvas widget for at different times in my game. Then I have a chunk of code that performs a zoom effect on the blueprint. But I don’t want to have to copy and paste a chunk of code a hundred times to achieve this for each menu.
I just want to be able to switch which widget reference I am using on the fly.
At any time I have a string which is the name of the widget class. But can I feed this string into the ‘create script widget’ maybe to switch to the required blueprint. And just have one chunk of code that does the zoom and the reference is the only thing that switches.
You can likely use a map. It’s one of the basic four variable types (single, array, map, set) in the dropdown next to the variable type.
Map from string to widget.
If you want more specific advice, please zoom in and provide a bunch of screenshots.
Thankyou, yes i think this is what i am after. However im not too sure how to implement it. You see here i have my current selected widget gets its text checked and then the corresponding reference to blueprint class is created.
so the ‘write script’ is connected to the create widget node which creates a reference to the script menu blue print so i can access the variables there.
I tried to follow what you said about mapping all the widget names as strings - but i need to be able to have the strings correspond to the names of other widget blueprints.
but not sure how this works here, i cant specify the name:
the string is the name of the blueprint I need to access variables for. But I don’t know how to set the value to the matching names blueprint? - it just allows me to select ‘widget Blueprint class’ as a type, but not the specific name of the blueprint. does this make sense?
i have basically 10 menus that i need to be able to pop up when i require. So the string is the name of the currently selected menu i need to be added to viewport. So i want to use the dictionary map thing to connect to the correct blueprint to be able to display.
@Ivan3z It’s not easy when the person doesn’t know C++. You can’t intuit C++ code as someone who’s never coded before (at least not to the point you can convert it)- you think people can since you can, but they can’t.
Yeah you’ve got what you need, you’re just missing the connecting pieces I think.
You’ll want a map of string → user widget class.
You can then fill out the values you want:
ie ScriptBreakdown would be mapped to ScriptBreakdown (using the images of what you did to convey which class)
After that you’ll just use the find node. If the find node finds something that matches (so in the example I’ve made that would be “Some Menu NAme”, “Another MEnu”, or “Pause menu”), the boolean will be true and the class will be whatever you’ve mapped it to.
I don’t want to confuse you too much, but you shouldn’t be creating a new user widget every time.
To avoid this, create a second map. This should be a map of string → user widget object. You don’t want to add any defaults to this.
Then we simply check if we’ve already created the widget for a given name. If we have, we add that reference to the viewport. If we haven’t, we create a reference, add it to the viewport, and store a reference to that in our map.
I think he knows exactly what he wanted to do (he answered his question twice)… But he didn’t have much confidence in himself. He just needed someone to confirm his ideas.
I really think he’s smart. I believe that if he puts his mind to it he can translate those 4 lines of C++ without problems.
I have seen many people on this forum with less knowledge than him.
rokenrock - I had a small follow up question if it was simple.
Now that I have access to the correct blueprint, I need to access the top level canvas panel in each. So would I need to create a second MAP node variable that stores the unique panel names? and if so what would be the ‘value’ type in the MAP?
The panels have the same names as the key names in the previous MAP node, just with ’ OuterPanel’ added at the end. So was thinking to use these modified strings to somehow call up the corresponding panel variable. All of those panels have ‘isVarable’ fyi.
Maps has a key and a value. There cannot be two identical keys. therefore they are unique.
I’m going to show you a trick. Maps and enums work great together.
So, create a enum. (Enumerate your UI) So in your Map the key will be your of enumeration type, and the value will be your UI reference.
I like this way, it is better than using strings as key.
This has several advantages over strings.
-It only uses 8 bits of memory
-You don’t have to write strings all over your code.
-It is easier to debug, especially in C++ because string literals are harder to find. (You can make a mistake writing the string and it is a disaster).
Ivans3z, its not that I don’t understand how to construct a sentence that solves my problem its about implementing it in unreal engine. Why don’t you just answer my question instead of patronizing me and giving me irrelevant information about enums.
the reason I am using strings is because I have a menu which contains many buttons that can be traversed. When I select a button I am using the button text to call the corresponding menu to be zoom transitioned onto the screen. So I am not only displaying the new menu but I am also targeting the canvas in that menu to perform a scale anim at the same time.