Download

How to stop the execution of a function until an specific event occurs

So I have a UMG widget menu that open when I select a move-able character. In this menu you can set different aspect of the character. One particular thing I use this menu for is to move the character around.

The sequence goes like this:

  • Click on the character
  • Pause the game
  • Show UMG widget
  • Click on “Move Unit” button
  • Hide UMG widget
  • Wait for the player to select the position
  • Set the unit to move to said location
  • Show UMG widget

From here you can click away to remove the UMG widget and unpause the game.
Think of it like selecting a unit in StarCraft and click on move button and then select a position on the map for this unit to move.

My problem is at “Wait for the player to select the position”. My idea is to wait for a “left mouse button” event in the execution to continue and the get the location but I don’t know how to wait on an event.

Can anyone point me in the right direction as to how to achieve this?

What comes to my mind is to make a Boolean variable and set it to true after the player selects the position then do a branch check to see if it is true before continuing.

Like said above ^
But I think it would be a perfect timing to start diving into Event Dispatchers & Interfaces for this kind of logic.

So I’ve been playing around trying to find a solution and boy oh boy I’m confused. SO I figured that you can’t get “Left mouse button” event unless you have a player controller or if you are a player controller. So that mean that only my “GODPawn” (which is my player) can access the event. But I need the event in my “CombatUnitMenu” which is where I hit the move unit button.

Since I already have an Interface for moving characters around, I’m trying to use it to send a message from “CombatUnitMenu” to “GODPawn”. But I already use the “Left mouse button” event in “GODPawn” to select the unit and the way it work is if I don’t click on a unit that I can move around, it deselect like this. I don’t understand how a combination of 2 event can trigger a behavior. That’s number one.

Number two, I’m trying to implement aTs_Ineffable solution by having a branch looping on itself like this but I have the error message “Both are on the same node”.

I’m pretty sure at this point that the way I’m trying to do thing is fundamentally wrong and that I’m missing something but I don’t know what or where to look for. I’m going to look at Event Dispatchers like silik1 proposed but I don’t think it will help much as I think my problem is where I put functionality and who owns what.

So I took a look at the Event Dispatchers and what I took from it is I could fire an event every time the “Left Mouse Button” event is fired but only subscribe to it in my “CombatUnitMenu” when I’m waiting for the player to chose a destination then unbind the event. Would that be correct?

This is precisely the usage.

For more theory on what the Dispatchers are allowing you to do here, I recommend you take a look into the basic theory behind Finite State Machines

You guys are genius! It works just fine now. Thank you all for your time. You will probably see more question from me soon enough.

Believe me I thought I’d found god when I realized the true power of message dispatchers.