Flow control like in a transistor

Hi,

I need to make one function fire when other one stops. That is to say, I need a Gate, which is open, when another event is played. It should work just like a transistor - nothing will go from A to B, until something is going from C to B. When the C input stops - A to B stops as well.

Is it possible?

There are XOR, NOR and such gates I believe.

I can find them only as booleans

The problem is that when an event stops firing it does nothing. And I want to somehow change a boolean when the event stops.

But is exactly how a transistor works. Boolean math, so to speak.
True, False.

If you use branches to check for whether conditions are true or false you can activate functions back and forth as you wish.

Ok I think I need an example :confused:

There is Event Tick that is conntected to a branch and further to Print String “Hello”. I set boolean to false and nothing is shown on the screen. Now, I want my Custom Function “ReleaseThePrintString” to toggle boolean when it is fired and when it is not.

Game begins. ReleaseThePrintString is fired, the boolean is changed and “Hello” is shown on the screen every frame. Now the ReleaseThePrintString is stopped. Even though, the boolean is still true and “Hello” still on the screen every frame. How to stop it? There is no functionality like ButtonPressed/ButtonReleased in this case…

Not as such, because unlike electrical engineering, code/blueprint execution is linear and discrete, not continuous.

Meaning, you can’t have two “flowing” paths. You only ever get one “flowing” path (which is your Tick, and which is always firing off events in sequence every frame).

You have to think in discrete terms. It sounds like what you want is for a function to be fired for a series of frames, and for the game to do Some Thing on the first frame it ISN’T fired.

How you set this up is going to depend on what specifically you want to do. For example, if you’re using an overlap event to trigger it (i.e. the player overlaps a fire zone or something) you may just want that actor to call the function every frame. If it’s for something like player input (every frame the player is pressing a key) you’d want to use the Press and Release commands instead.

As to your specific ReleaseThePrintString example, you have to understand that functions cannot be “stopped”. A function is like a gunshot; it’s called and immediately fired, one time, and that’s it. So what you’d probably want to do is have your Tick function, AFTER performing the check and discovering that the bool is true and it should Print “Hello” to the screen, have it immediately Set the bool in question to false. This way, every frame, ReleaseThePrintString will have to be called again or the printing will stop… this way, whatever function is calling ReleaseThePrintString must be doing so every frame for the status to continue.

Yes that’s exactly what I mean. It’s clear now how it works, thanks.

Yeah, right that should work. However, when I call my custom function whenever I want and the tick is firing simultaneously, I have no idea what will go first. So, when I set the boolean to true in my cutom event and event tick checks the condition, than sets the boolean to false at the very end of its sequence, I have no guarantee that my custom event will manage to set it back to true before the condition in event tick is checked again…

I BELIEVE that the Tick always fires last in a frame… but you’d have to check.

What I do know is that it’s consistent. i.e. if your experiment reveals that the function call is being executed after Event Tick, it will ALWAYS be that way. It’s not arbitrary or random. So if you set up a system that works assuming the Tick is fired last, or fired first, or whatever, it will continue to work that way. It won’t sometimes-work-and-sometimes-not-because-the-tick-fired-first.

What, specifically, are you trying to accomplish? I think knowing the specifics might help us come up with some more ideas.

Oh, I thought it isn’t 100% predictible. I will do the tests then ^^.

Anyway, is there something that allows me to check when raycast is not hiting object anymore? Like On Actor End Overlap for raycast hit.

I wish there was, it would make certain things a lot easier for me.

The setup I think of could be something like this:

A raycast hits an object and saves it in a variable. Every frame there is a check if the object being hit now is the same as the one saved in a variable. If True, nothing happens. If False, it means the raycast moved to another object. In that case, on the saved object a send message is called (that will act just like an event called when a raycast is not hitting the object anymore) and after that the new object is assigned to a variable.

I will try both to see how they work.

Ok it’s working but… Event tick in debug view has a constant red line showing the flow. When I fire my custom event, Tick slows down and fires with pauses, like lagging. It doesn’t allow smooth transition in that case. Is it something wrong for optimization, when Tick is slowed down and lags?

If you need reference to gates Flow Control | Unreal Engine Documentation and there is a multi gate

Tick is consistent with your Frame Rate, the “lag” you see in the Debug view is cosmetic only, it would be unfeasible to show a “pulse” every single frame in the Debug view so it just displays it as solid red slow pulses. This does not mean your Tick is not “ticking” incorrectly. This Debug view is only there to help you visualise the path of execution, i would never trust it for accuracy outside of that fact. If you want to Debug Tick yourself you will need to setup proper debugging techniques like Breakpoints and/or print strings etc etc.

It almost works. The problem is that event tick from Bluprint service (behaviour tree) fires about twice per second. That’s far too rare. The change in states happens too slowly. Anything I can do about it?

Nevermind, I found it ^^. Thanks for all the help guys.

(Behaviour Tree -> Details (Blueprint Service) -> Service -> Interval)