Puzzled by this blueprint logic

A few of you here that have been nice enough to help me with this project know that I have been trying to learn UE for the past 3 or so months, and honestly, I love it. I’m not even a gamer, but I love the things you can do with the engine and all the applications for TV and cinema besides games.

And one of the things I love the most, and it has become somewhat of a game in itself for me, because I want to get better at it and conquer it, is the blueprint system. My brain is not wired for writing code, at best editing obvious tags in small HTML pages here and there. I just love connecting all these nodes and seeing what they do, and how they affect others, and how they are not always logical. And that’s my point for this post, because I want to understand the logic in this widget blueprint, and why it’s working in a reverse logical way.

This is a widget blueprint, with three images and a basic animation. It’s like nice motion graphic that says “Read More” when the player hovers over a frame in front of them at less than 500 whatever the measurement unit is, so in plain terms, something like 2 meters. That animation has to be triggered by a line trace, something that me and my team have used to oblivion in this project.

So here’s one version of it:

As you can see, in this one, I have used, after the line trace nodes, an “? is valid” and a branch node. But I bet when you looked at it for more than a second, you got drawn to the obvious blunder there. In the Is Valid node, I sent the wire to the branch out of the “Is not valid” output pin instead of the “is valid”. And then once again, I connected the “False” output from the branch to the play animation node.

So by looking at this, you would assume this doesn’t work. The point of the node flow is to tell the game that when the player is closer than 500 units to the actor, that if it’s valid that it hit the actor, then it will play the animation.

However, the way that makes sense, meaning, going from the “? Is valid” node’s “Is valid” output to the branch, and then from the “True” output of the branch, simple doesn’t work. In fact, I think when I doit the logical way, the animation plays when the player walks backwards out of the line trace area.

Then here’s another similar version of it:

As you can see, this one uses a Cast To the specific actor I chose, and when the cast with the line trace is successful, it should play the animation. Therefore, the Cast To node should go from the top nameless pin that assumes the line trace hit the actor, to the input of the play animation node.

But in the same way as above, it does not. It causes the opposite. However, when I do it the way you see here, going from “Cast failed” to the play animation node, in fact, does play the animation when the player hit the line trace area.

So this to me doesn’t make any sense, but is this a bug, or is there a logic here that I’m not following? Is it because of the specific type of blueprint? And I want to add, even though the first example doesn’t show as compiled, both of these compile with no issues, and don’t give me an “accessed none” error when I stop previewing the game.

So if someone can explain to me how this works it would be great. I tried all sorts of things to make sense of it, but I can’t.

running heavy functions are not recommended to be ticked without any tick execution limit… at least do it with a delay of 0.00005 sec

Thanks for the tip. Actually I still have trouble understanding fully what an “event tick” is, or just a “tick”, but I found it that it’s the only event I could call to start the line trace and all the actions after it.

However, would the tick frequency affect the logic of the line trace and make it reverse? And how would I add the delay you mention?

delay and frequency are the 2 sides of one coin, you can use them for any reason to make the performance better.

Event tick is the event which runs the tick itself, the tick is actually a legal infinite loop which execute anything exists in it on ps/bases

The issue may be that you’re triggering animation multiple times a second.
I’d suggest reviewing the logic so that it would only be called once when the conditions change. Something like:

1 Like

If you need to have a constant collision check like firing a trace every tick, then the better option is to add a capsule collision to the player. Scale and rotate it to resemble a tube projecting from the camera or a sphere suspended n units from the camera. Realistically you’ll want said collision attached to a spring arm so that it contracts as it collides with your world. Similar to the 3rd person camera. You don’t want it penetrating actors, say behind a wall/door and triggering them.

To trigger special events you’ll want to create a new collision type in project settings → collision. Set your interactive collision and your special actors collision to this type. The collision settings should be block all, overlap the new collision type.

Going further you’ll want to use a Blueprint Interface. Name the function something like Interact.

In the character class create a Begin overlap event for the interactive collision.

On Begin overlap: Get overlapping actors → For each loop w/break → Does implement interface (your BPI). True: Call BPI event on the actor (e.g. Interact) → BREAK.

BPI event Interact: execute animation etc.

Actor collision, End overlap (our new collision type): stop widget animation etc.

The BPI reduces the need to Cast.
The Overlapped Actor controls all its logic internally. This reduces code bloat in the character class.


Tick… A tick is a frame. If you’re running at 60 FPS, then that’s 60 ticks a second.


2 Likes

Sorry Tuerer, I don’t follow the logic here either. I actually just reproduced it in my blueprint, but you are going from the branch False pin to that set “has been hit” variable, and that’s the one that plays the animation forward. So I still don’t follow the login, because it should be going from the True output of the branch node, because it’s true that the line trace hit the actor. Does that make sense?

And I see also that you put another animation to play the animation backward, but I tried that many times, because I would really like to play that animation when the player goes out of the line trace area, kind of like when you put a collision box and you have a “On component begin overlap” node that triggers some action, and then the “On component end overlap”, which in that case can play an animation in reverse. So the “On component end overlap” is activated only when the player first overlapped the collision box and then walks out of it.

However, in the case of the line trace, if you set an animation to play in reverse when the player is not hitting the actor specified, that would mean that it would have to play the animation in reverse all the time when it’s not hitting that actor, meaning the whole level other than that specific area. Makes sense?

Answers and thoughts on the original questions.

Sometimes bad code appears to work. Thorough testing will usually show otherwise.

Unreal Units are Centimeters (cm). 500 units/cm is 5 meters.

For example:
Your trace could be hitting the character. Thus a False positive. You should always Ignore the instigator of the trace.

Your conditional logic flow is off, If the intent is to animation only on valid hits.

If Is Valid (hit actor) is not valid, then the Branch (return value) will also be false.

If the actor is NULL then it isn’t valid. Only when the trace hits something will the hit actor result be populated.

Correct flow is Branch (Return value) True: continue. If we hit something, then do additional checks. Otherwise you’re wasting processing.


Second BP just as the first will only animate when it doesn’t hit what it’s suppose to.
e.g. BP_PicProdDash actor.

I don’t follow the logic here

The logic is that if you have already launched the animation but you’re still facing your actor, you don’t launch it again, you let it play and finish. And vice versa, when you stop facing the actor, you reverse the animation only once, until you face the actor again.

Think of it as a light switch. You cannot turn on the light if it’s already on.

Oh thanks for reminding me that, somebody told me a few weeks ago and I had forgotten. Then definitely there’s something wrong with my mesh, because if I had to guess the distance from where the player first hits the actor with the line trace, can’t be more than two meters, I mean visually.

As for the other recommendations, thank you, I’ll definitely keep that in mind, but in this project we have tons of those line traces already done, it would take forever to replace them.

I’m sorry, I edited this post because I was wrong, your node setup actually kind of works, but one caveat. The starting point of that animation has all three objects at render opacity 0. However, when applying your setup, on preview you can see the graphic like half way or something like that. It looks very faint and it shows all three layers at once, which is not great.

But the good surprise is that indeed, it plays the animation in reverse when the player walks back and out of the line trace area, and it plays it fully, so the graphic eventually disappears. But every time I start previewing the game, it shows it there half way. Any ideas?

You’re potentially crushing your performance right out of the gate then.

Probably, if this was a regular game. We’re just doing a thing that is rather simple, not too much geometry or motion or anything. But I copied and pasted your suggestion in case we start another project that may need similar things, and then we’d have more time to implement your way.

OK guys, I’m going crazy here. I’ve spent the last 5 hours trying to figure this out and I can’t. I wasn’t even posting to learn this particular thing, and thanks to posting about the reverse logic, now I know how to trigger a reverse animation when leaving the line trace hit area, so thanks a million Tuerer for that info!

So applying your node setup to my widget blueprint, this is what I ended up with:

And that works almost perfectly well. The only problem, and unfortunately is a deal breaker, is that when I press play to preview the game, the frame on the wall that has to show that animation when triggered by the line trace, shows this animation in a weird state, like half way through, but not exactly, because this shows all three textures of the widget at like 50% opacity and all drawn at the same time, which never happens in the animation, because they are shown at different times.

So I have googled and tried everything, even copied most of that node setup with line trace and everything, and pasted it on the blueprint actor that is actually the frame on the wall, which is in the main and only level. So this is what that one looks like:

In this one, I set the same node setup as Tuerer showed me for the widget blueprint. But in this case, I set the Alpha channel in the Rendering>Tint color and opacity option to 0, but in the graph, I’m telling it that if it hits the actor with the line trace, then it has to change the tint color and opacity to everything 1.0, which is what it is by default.

And in the other node, the one that was the reverse animation in the other blueprint, now is the one that sets the alpha channel to 0.0.

Well, the result from this is that the widget never shows at all. It seems it doesn’t care if the line trace hits the same blueprint actor as the other one, it doesn’t follow the order to set the opacity to 1.0.

Of course I would prefer not to even setup these nodes in the blueprint actor and only have the initial setup in the widget blueprint, but no matter what I do, when I press play, that ■■■■ graphic shows at 50%.

So I’m completely lost. Can anybody make any sense of this?

I would try using collision box with start/stop overlapping events, timer and linetracebtchannel. Of course with debug enabled in linetracebychannel node.

Sorry, I don’t follow. If I use collision boxes, then why do I need the line trace.

However at this point, I’m more focused on how to make the setup from Tuerer work, because I’m sure it’s just one small thing I’m missing somewhere. That is unless the editor has a glitch in this version of UE, but I hope it doesn’t, because I’m really close to the solution.

Linetrace is only a function. You can use collision box only or together with Linetrace. Collision box could be used to start a timer that will use Linetrace periodically when your character is in range with the place it will interact with. It is about using functionality only when it needs to save time of the game for other actions. When overlapping end event will occur the script must turn off the timer.

Here is demo with collision boxes only. Link will be active only for 6 days.

Thanks man, but a bit too advanced for my current knowledge. I’ll definitely give it a try another time. But the good thing I found the solution to Tuerer’s node setup. Instead of using the Render Opacity track, I added a color and opacity track and manually entered all the keyframes from the render opacity track, then deleted the latter. And now it works, it plays both animations, and when the game starts, it doesn’t show the half way messed up animation.