I have 2 functions - A is continuous.
B one execution.
Both use and need the left mouse button.
How do I use B to close A without it prematurely ending the A? (Sequence node was not the answer )
Speaking more in depth the A function produces a menu, the B function stops the menu and this is happening in my blueprintwidget. The second click (function B) needs to spawn a mesh and stop the build menu (Function A).
Function A is fully working using functions within it.
First of all, what is a continuous function? A function called on Tick or very often?
If so, why would a ticking function produce a menu to start with? Popping up a menu is something that you do once. Perhaps you want to look into other Flow Control nodes.
Apologies I’m pretty new to programming and blueprints so its not using on tick but basically left clicking would start a function that wont stop till I tell it.
My intent is to achieve the same effect of an RTS. so when you click to build, the ghost of the actor disapears (green when you can place and red when you cant)and places an actor in the world. I have a function for launching the menu and closing
But I cant close it. How would execute it without conflict?
I hope that this is inexperience of programming/scripting for this statement.
in programming when something “won’t stop” particularly on the main application thread, then nothing else can happen at all on that thread this is generally a situation of “infinite loop” and to the user a “hard-lock” (in specific systems called interrupts these can be stopped, but otherwise the system will process that and only that) and in C derived languages a function is a single execution path, that starts, does a task, and then ends. they can still call other functions, but think of them as a single line, and it is only through loops, and branching we deviate from that line.
for applications in general typically the concept of states are used, for example you would be in State_Menu, State_MainGame, or State_MainMenu. some of these states in the Engine are done through levels, but others are done through programming/scripting logic. a widget can be part of a state, or an entire state on its own. so when you open the widget (which you only have to do once to change the state, and then close/destroy it to change it back)
this is probably why @Everynone was asking about the widget being opened in Tick() because that is the “sanest” way to do something continuously in the Engine.
to the specifics of what is going on:
are you using Enhanced Input, or the project settings method (this cannot be used in engine versions after 5.1)?
is the widget intercepting the input, or are you keeping the input living in your controller/character?
you can have like a boolean
that gets set to true when you open the widget
when you hit the button/input that you use to close the widget
check that boolean. if it is true then close the widget
and set the boolean to false.
a “simpler” way to do this would be a “flip-flop” node where when the function is fired for the first time path0 is used, and if that same exact function is called again path1is used instead.
the reason to use the boolean or some other state determining variable is if you want to check on the state of your widget for other things,
ex: like in a single player situation you could pause time while a specific menu is open, and you can check to see if that menu is open by checking an accessible state type variable (boolean, enum, raw int)
So firstly, your reply has been very insightful so thank you for the very detailed response it has deepend my understanding.
I’m using enhanced input because i’m in 5.2/
I have a mouse click event within the widget (to spawn a mesh ghost) and then a second in the controller (to spawn the mesh and then immediately close the function)
I understand and I haven’t actually tried to utilise the flipflop node. Ill try to implement what you have told me
casting in blueprints can get expensive, and doing it every time there is a click sounds like a potential lot of them.
for something like an RTS there is typically only one of the controllers that is cared about for any given player (if you are going to have like spit-screen then this would get trickier) instead of Cast() every time there is a 'mouse down event` try just receiving a cached variable.
have a BP_RTSController reference that is public accessible in the widget (you can create a getter and setter if you really want), and when the widget is invoked by the user set that BP_RTSController reference. then in the OnMouseDown (shouldn’t this be an event?) get that cached reference, and if you want sanity run it through the exec version of isValid()
in your flipflot() screen shot:
the event is invoked.
if ( (BP_BuildComponent.CanBuild) && BP_BuildComponent.bIsBuildModeOn) )
flip-flop
*SpawnBuild(BP_BuildComponent)
*StopBuildMode(BP_BuildComponent)
what does it mean for bCanBuild to be true but bIsBuildModeOn to be false? in my mind I can see the inverse, but logically this could be a cascading if (if->if)
the first if( BP_BuildComponent.bIsBuildModeOn ) would be mostly for sanity, while the if( BP_BuildComponent.bCanBuild ) would be to see if the the building needs to be spawned or the mode exited.
though on looking at this, and giving it some thought, it might be confusing to the user ( where “I Want to place a thing” → OpenBuildMode → SelectThing → “I want to place it here” → placeThing → Build Mode still open → click again → BuildModeExits → Nothing is placed ). I would strongly suggest tying exiting the BuildMode to some other input like Controller_B, ESC ( while working with PIE you would want to map this to something else because ESC is reserved in PIE for ExitPIE() then map it back at the point of release ), or a different keyboard key.
you could take a look at the Cropout Sample Project ( Epic Games Launcher → Unreal Engine → Samples → Cropout ) where it is from my understanding an “RTS” built completely in blueprints that includes a build system. you are free to reference, modify, extract from, and technically repackage any part of the Epic Game’s Samples around 22 minutes they go over building
While I haven’t solved the problem It has helped narrow it down and I tried to really understand what you have provided. It has really helped me in other areas so thank you
I have explored the cropout project and im amazed at how differently the logic is implemented! At the stage in my learning I think I need to make sure I’m doing things in an optimised way so I’ll look at implementing some of the types of logic you suggested . (Ill Update when fixed)