Link to large image: http://torquemod.com/next_map_broken.jpg
So I’m still struggling with getting my “Next Map” button in a UMG to work properly.
Quick explanation: I created an actor that I place in the world with an exposed variable name. In a map called “Mission 0” I drop the BP into my level and type “Mission01” into the “next map name” slot. Inside a UMG menu called BP_WinMenu (pops up when you accomplish the end level goal) I created a button called “Next Map” that when pressed should take the “next map name” value from my actor and pass it to an “Open Level” node.
The problem is that its not working. I know I’m getting the correct value from my actor because if I print screen the value it returns “Mission01” like it should so I’m guessing something is being lost when I reference the value in the UMG. I followed this documentation on how to reference another blueprint: Direct Actor Communication Quick Start Guide | Unreal Engine Documentation
and as you can see in the screenshot, its allowing me to reference the “Next Map Name” value inside the UMG. Problem is the button still doesn’t work. If I pass the value into a Print String node I see nothing and if I click the Next Map button it loads my default map which is the Main Menu.
No idea why things still aren’t working.
is the ReferenceSaveGameActor valid when you try to load the level? Can you place a breakpoint or use the isValid node to check?
Without knowing exactly all the technical details behind the scenes, I can probably point you in the right direction to fix this - as the same problem exists when trying to talk between the UMG components and, say, the level blueprint. The UMG component isn’t actually a thing in the “world” and therefore has trouble directly communicating with other actors which are. In fact, I’m not really sure how your “Reference Save Game Actor” variable is ever getting linked up with the placed actor on your map in your example. The UMG component can communicate back thru its owner (you … more specifically, your player controller) though really easily.
What I’d try is setting up a custom event, or an interface, on the player where once the button gets clicked you first send a signal over there to open a new level. Then, in the player blueprint, go read the value of Next Map Name from your BP_SaveGameActor and fire the actual Open Level node outside of the UMG component completely. Make sense?
Ok yeah that sounds good. I could always fire the open level command through the save game actor then.
How do I go about getting the button in the UMG to trigger an action in another blueprint though?
Inside my save Game actor I now created a function called ChangeLevel which runs the OpenLevel command but I’m not sure how to get the button to run it.
Its seems that it is Invalid.
Larger image at http://torquemod.com/Invalid.jpg
I added this setup and its returning “Whoops!” instead of the “Print String!”
That means it is not set.I would still try to have the level loading logic elsewhere like Hawk says.
how do you get the button from the UMG to trigger a command from another blueprint?
Your user widget needs a reference to the blueprint where the level loading will be. This means that for example if you load the level from your character blueprint, your userwidget should have a variable of your character type, and set it after creating the widget. Then you can call any function of your character blueprint from you UserWidget.
Another way is to load the levels in your game mode, which can be accessed from anywhere using the GetGameMode function. That way you don’t need to have a variable of it in yor UserWidget.
Take a look at this tutorial - YouTube
Thanks a lot man. Still a total noob to blueprints. Following a tutorial is simple but when it comes to figuring out how to do things on my own I’ve still got a lot to learn.
Ok so I’ve tried to set this up so that the Next Map Name is now stored and executed from the Save Game Actor blueprint. The script works because when I call it from the Event Begin Play with a delay of 3 seconds it loads the map properly.
For some reason though I still can’t get it to work referencing it from the UMG. Here’s a screenshot showing my entire setup:
When I click on my Next Map button in my UMG though it doesn’t do anything.
Any ideas what I might be doing wrong?
I still don’t see you passing your SaveGameActor reference to the UserWidget.
Wherever you are creating the Widget and adding it to the viewport, you need to set it’s SaveGameActor Variable, or it will be empty:
I’m confused. This is a Function not a variable so there’s no Set and Get options. In that exact screenshot you posted I’m calling the function. and in the last part of my screenshot above I’m telling the function to use the SaveGameActor BP in the details panel under Target BP.
If it wasn’t working I wouldn’t be able to access the “Change Level” function that’s inside the SaveGameActor BP.
I don’t know how else to pass the actor to the widget.
This is when I actually Create that WinMenu UMG which is inside the HUD’s Event Graph…
I’m not sure how I’m supposed to Set a function that’s called inside the UMG from the HUD BP though.
Yeah I thought that was strange… I just specified its target inside the function itself though so I didn’t think I had to specify it again…
I figured that target of self would work because its specified inside itself.
Infact when I try to specify the target again it doesn’t let me pick anything…
I also tried adding a default value to the input but when I did it just made it blank again after pressing enter. Also checking the Pass by reference box just breaks the script. Really confused.
I would have thought that if I’ve already specified the target blueprint inside the function that when I place it inside the UMG it would already be filled in instead of asking for a target. Also I cannot drag a wire from the pin to get the correct target… it doesn’t show in the list.
the TargetLevelBP function, why it doesn’t have an input variable for TargetBP?
You can call the ChangeLevel function inside the TargetLevelBP function, but it doesn’t appear to be getting a value.
I think I’m just going to watch a bunch more tutorials on Blueprint cause I’m obviously missing something that should be quite simple.
Thanks for the help though Ghar. And you too Hawk.
So I followed all of Horus Heretic’s awesome UMG tutorial videos ( HorusHeretic - YouTube ) hoping that I’d learn some new things (which I did) that would help me solve my dilemma (which I didn’t). Sadly I’m still clueless. For all intents and purposes, what I’m doing SHOULD work. I don’t know why its not working when I can clearly execute the script in my Saved Game Actor blueprint from my WinMenu widget.
I made a basic project with this behavior, but I used the Character Blueprint to load the level and add the widget to the viewport.
The part you are missing, is after adding the widget to the viewport, passing the reference of the blueprint that loads the level to the widget. (In my case, set the MyCharacter variable of the widget and pass self as input)
(I created it on a mac, but it has the only files needed to run on the PC. You might need to set the GameMode in the world settings)
a little off topic: here’s a link about adding and removing the widgets to the viewport and level loading. I didn’t know about this and found it very useful because I wasn’t removing the widget before opening the other level, and the widget was still showing up:
Ghar you are truly a helpful individual thank you so much!
I don’t get more time off till Sunday but as soon as I get a chance I’ll go over your help project and see if I can figure out my mess. The weird thing is that when I tried to make the function target itself something went wrong… can’t remember off the top of my head what it was but I just remember it was odd. Maybe its the lack of sleep every time I work on the project
I’ll post again as soon as I get a chance to review everything!