Blueprints nodes not always complete before the next node in the line is processed. How do I detect reliable when a node is completed? Also any clue to know what node will give me issues with this?

Now, after two months of developing my game using blueprints, I’m finding time and time again that some nodes don’t get processed immediately. Which first will break the blueprint logic, second, just makes me lose a lot of time figuring out why the stuff I know should work, doesn’t work.

Last wild node I’ve just found, and just spent one hour scratching my head trying to know why it doesn’t work, is the “Set Anim Instance Class”

So this pesky node will not complete in time till the next node will be processed.

Doing something like this will fail the cast and block the blueprint logic

But adding a delay node will result in a successful cast

There is no indications on what node will have this behavior. On the node description, there is no clue for the user that the node will not be completed immediately.

So there may be other nodes out there that have same behavior.

Anyway, using delays is not an option form me, one doesn’t know the player computer specs, maybe a delay of 0.2 is not enough on their machine. Did I put a delay of 10 seconds just to be sure it works? That will be stupid.

I’ve tried using “tick” to check if the variable I’m setting with that node is not null, then once it returns true, I’m setting a boolean to true, and then continue with the logic. This cumbersome. I need to keep track of all these booleans all over the place. Not fun.

Ideally there should be a node that waits till a task is complete then continue, like the delay above but instead of waiting for a set time, will wait till the previous node is finished. There are nodes that do exactly that, see bellow.

I’m really curios why this node behaves like this. I’m using nodes that have a clock icon, especially the async load nodes. both “async load asset” and “async load primary asset list” will block the blueprint execution on the line they are on and then resume when the load is completed. (which may take several frames or seconds)

image

Is “Set Anim Instance Class” bugged?

My question is what are the best practices to figure out when unreal has finished some task requested. There must be a practical and correct way to do this. I can’t imagine this happening just to me.

Edit: Now that I’m looking at the two last nodes, they have the Completed output, what about adding that to all these problematic nodes like the “Set Anim Instance Class”

Edit: I’ve fixed the example as there was a mistake in how the animation class was accessed. This is an example node structure just to isolate what I’m talking about. I have off course noticed and tested this in a complete working blueprint structure

1 Like

I can only guess here because I’m not deep enough into Unreal yet, but if I compare this to .NET for example, you will run into such problems as well. When you access stuff like animation or basically anything that happens in the GUI (in order to stay at the .NET example), you’ll always have to invoke that on a different thread (GUI-Thread). So my guess is, some of those Unreal functions we use will run concurrently in different threads as well.

In your example above, I don’t know what SetAnimInstanceClass does, but if it manipulates UI, chances are high there’s threading interop going on. Usually in .NET, instead of setting a delay (which is bad for the reason you mentioned) you would create some kind of callback mechanism which tells you when the cross-thread action is done and then you can react to it in your working thread.

So whatever SetAnimInstanceClass does, if you can think of a way to capture when it is finished, you could then have it trigger an event and when handling that event you can do your following CastTo… logic.

I’m not entirely sure how the best practise for handling asynchronous operation is in Unreal, so there might be better solutions than using an event to flag you’re done, but that would be my first attempt.

Just out of curioisty, try something like this before the SetAnimInstanceClass node (without the delay):

  • Does it return true both cases?
  • If it returns true after a delay, is there anything else setting the anim class?

Yes, that is exactly what I’m trying to find out. How to know when a task is finished. The blueprints nodes are laid out one after another. But as you have said, tasks are performed at different times, or may take longer. That node is setting an animation blueprint class on a skeletal mesh. Is the blueprint that have the walk, run animations, stuff like that.

I’ve tried that. If the Skeletal Mesh Component doesn’t have an Animation Blueprint, the print String will print null. If it already have an Animation Blueprint it will print the information of this class, offcourse, not the new one.

So in my top example, the cast will fail either ways because the animation blueprint is either different or not existing.

but the issue here is how to precisely delay the next node in line, after Set Anim Instance Class? There must be some way to listen or ask unreal to tell you when it managed to finish the task.

A simple but certainly not optimal way would be to use busy waiting. In SetAnimInstanceClass, just add a while loop and let it run until your new animation blueprint class was set.

can you show an example of this setup?

I wonder about the casting you do. There’s your skeletal mesh component, for which you set your AnimInstanceClass. Then you cast the Skeletal Mesh Component to ABP_Manny class. It is interesting, that you do not get a warning here as I do (4.26.2 in my case)
At least for me, this will always fail casting. Instead, doing GetAnimInstance helps.

grafik

I did some testing: this way it works, but In my case, the cast always fails if doing from skeletal mesh component directly, even adding a delay like you do does not change this.

I don’t believe it is because blueprint execution proceeds without having finished first. And sometimes, it is also caused by referencing objects, that are not yet ready at that time. That’s the situations, where simle delay nodes are often found in code, but as you say, this is not really a good option.

I meant something like this. Again, it’s a bad solution because you want to avoid any delays in general, but that would at least ensure you wait long enough in all scenarios.

This doesn’t work – you can’t cast a SkeletalMeshComponent to an Animation Blueprint.

There’s no delay occurring in SetAnimInstanceClass, you’re casting the wrong thing. As herb64 says, you need to query the GetAnimInstance of the mesh before the cast.

ah, yes, sorry that was a mistake in my example,was late at night and I wanted to show what I was talking about and failed :smiley: . in the code is offcourse, skeletal mesh, then get anim instance.

I will try to update the example later on.

I’ve been using blueprints for a long time and I’ve never had any issues with nodes not executing in the perceived order. Usually when an action is not immediately executed you can tell by having to bind a delegate or some nodes have extra outputs like the Async loading example.

I’m looking forward to your example.

1 Like

The example is the argument of this thread.

But you probably didn’t read what I’ve tried to explain or you didn’t understand. The nodes will execute in order. Is not this the question. In this case the blueprint execution doesn’t wait for the previous node to complete correctly. It will continue in order, but because the variables are not set correctly by the previous node the logic will fail.

I’ve fixed the screen because the example had a mistake as pointed out by someone else. Is down bellow. I’ve added the correct “Get Anim Instance” as it should had been

No I did read the previous answers and since your example was incorrect with the wrong casting there was no argument.

I did some testing similar to this example and the anim instance always returns a valid reference and the cast succeeds, I even tried tests where the mesh and anim class are not loaded in memory and had to load them from a soft reference.

I took a look at the code and I didn’t see anything that can explain the result you got, however I found a delegare you could use perhaps in your case to get notified when the anim instance is initialized. Bind it before setting the anim class.

i’ve did the exact test you have shown me and it worked also on my side. There must be something else here. I need to get back to the drawing board to see what is going on :slight_smile:

1 Like