Delay 0 Fixes VALID Variables Returning NULL

Today I’ve ran into two weird errors, to me made no sense. The first screenshot shows me trying to get a widget refrence, the variable is connected to the “create widget” node. It threw an accessed to none error, I put a get valid node and tried many things to see if it was == none or null but it DID have a value. The second screenshot shows me trying to make a custom event for the child to use but for some reason it didn’t fire and for both scenarios I tried doing the same thing in another blueprint and it worked perfectly. BUT putting a delay 0 when the event/function fires fixes the variables. Could this be a bug or corrupted-ish blueprints?

312802-screenshot.png

1 Like

It’s probably to do with the timing of various blueprint relative to each other. Some variables aren’t quite getting initialized before you check them. Changing the compile order could have an effect on that, not so much putting a delay of zero.

If you do have problems with one blueprint needing to wait for another blueprint, it’s better to code the wait in explicity, for instance a while-delay macro, rather than guessing a delay value.

The problem with the delay value approach is you really don’t know how it’s going to run on very different hardware.

Thanks for your detailed explanation, Later I will try out what you suggested and will respond accordingly!

I tried what you said and it stopped the errors but the variables still return null

If you wait for a while and still get null, then you’re just not assigning it :wink:

When you get the null error, click on the right hand end, that takes you to the offending node.

What’s it’s telling you is that node is getting null ( obviously ), not matter how much you think you have initialized it. You just have to trace things back until you find the spot with the buggy code.

EDIT: Suprisingly often, this can be cause by timing issues, but the rest of the time it’s just plain the variable not getting set.

wdym? i have a while loop checking if the actor is valid and if it is it stops the while loop and executes the code

This solution is for when you have a timing problem. If the while loop never finishes, then you have a bug ( ie the variable is not getting set ).

PS: It’s much better with a while delay macro. If you just use a while loop, the editor ( and your game ), will probably halt at some point due to infinite looping…

Do you want to know how to do while macro?

It is the timing, thx for answering in detail, i fixed it using the event dispatcher node