How to set a variable to null

How do you set a variable to null in the Blueprint Graph?

My character has a reference to an ActorType in the world. It starts out null, but when hits the trigger overlap of the object in the world it is set on it. That part works correctly,

But, on leaving the overlap I want to set the object to none. The breakpoint hits, but the variable value is not changed to null, it remains the same as before.

Going to the trigger overlap of a different object works, it is set to the new object. ,This is what I have now.

Just set your variable right before that function without having an input.

If that doesn’t work, then you can use a second variable that never gets set as your reset variable.

3 Likes

That seems like a workaround also. I think that would work though.

I set a second variable, a bool which I branch on but it seems like a workaround. It would be better to be able to set an Actor to null.

That is what Zuestiak said. That seems like a hack, there should be a way to set a variable to null directly.

1 Like

You have to set a variable at some point, whether that is using a node that says “Set Variable = Null”, or using a “Set Variable with no input” or “Set Variable with Non-Set Variable”. It is all the same thing.

I took a screenshot, it shows what you are saying in your 2nd suggestion. Setting a variable with no input.

It does not work. The variable is not set to null, it retains it’s last non-null value.

Why don’t you have a variable that is set to null and just have that set the elevator like you have self?

9732-example.png

Well even if you code it you would have to set it to NULL and NULL is a defined variable. So in a way its the same you have to have a defined variable that equals something or err nothing in this case.

which was what I had hoped the screenshot was trying to show sorry if it was not a good example. But I am with you on this Zeus you have to set it to SOMETHING be it NULL to start before you set it to a usable value.

Your function is lacking the input. That isn’t what I am saying. The variable that goes into that function has to be Set somewhere, and that Set node needs to be blank.

Obviously you can’t do that inside the function or it would mess with the begin overlap side as well, so just do it before it enters the function.

Yeah I used to wonder why there isn’t a Null function as well, but it is all the same in the end. Maybe the devs could put a little extra note that says no-selection/input = null.

this doesn’t work with objects or actors.

I think some kind of explicit set to NULL and check for NULL is pretty important. I tried using an unset variable in my class named NullActor as a hack to have a way to set/check for NULL but I don’t think that works in object =. Why not have an explicit NULL if hacks are likely to confuse people? Great question; curious why Epic hasn’t responded to this one. Makes me wonder if it’s time to just go for C++ directly instead of blueprint.

this does not make any sens, blueprints are C++ based, there should be a NULL value

This is so needed.

This is really needed! The above are workarounds.

1 Like