[4.3] How to perform a Null check now?

How on earth do you perform a Null check now?

if targetObjectX != null :
	targetX = targetObjectX.global_position.x
else :
	targetX = parentBody.global_position.x

Doesn’t work

and

if is_instance_valid(targetObjectX) :
	targetX = targetObjectX.global_position.x
else :
	targetX = parentBody.global_position.x

Also doesn’t work

The heck is the new syntax for this?

Can you provide screenshots for the error messages of each?

The error is

"invalid access to property of key 'global_rotation' on a base object type of 'node3d'"

That isn’t really the problem, though, as it works when targetObjectX is not null. What I’m trying to do is make it not attempt the code when it is null.

The syntax didn’t chaged for that, is exactly like is in your first example, the error you put after didn’t seems to come from the code you put because says about global_rotation and your code access global_position property, so will be better if you put the exact error that come from this code or put the code that generates the error from your second comentary

1 Like

Ah, correct- I had that in my clipboard from searching for a solution. Same problem, different section.

if “!= null” is how you’re supposed to check if something is null, then it isn’t working

Can you share the project? Because if “x != null” is not working this can be a bug

Are you absolutely certain that it’s ‘!= null’ ?

if targetObjectX != null :
	targetX = 1
else:
	targetX = 0

makes targetX 1, regardless of whether or not targetObjectX is null

…Apparently it’s not working because targetObjectX being empty doesn’t make it null, it makes it… “<GDScriptNativeClass#-9223372022778690903>”

Maybe it is a bug.

Oh, no, I just did it wrong.

I had

@export var targetObjectX = Node3D

instead of

@export var targetObjectX : Node3D

Always post your full code, kids.

1 Like

What class is the “targetObjectX”? Because be empty is different from being null and also null is different from a freed object

1 Like

I just Cast it wrong when creating the variable (I think that’s the term).

Thanks for the assistance!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.