Export keyword and assert

Godot Version 4.2.2.stable.mono

hello, how to ensure that a variable is not null in the inspector?

like set it as required and not being able to launch the node if this variable is not defined?

It’s not possible. The best you can do is to generate a custom warning that will show next to the node in the Scene dock using Node._get_configuration_warnings() Read the documentation to understand how it works.

1 Like

Something like this?:

using Godot;

namespace Scene15042024;
public partial class Scene15042024 : Node2D
{
	[Export] Node node;
	public override void _Ready()
	{
		if (node == null)
		{
			SetPhysicsProcess(false);
			SetProcess(false);
			GD.PushWarning($"node in {Name} is null!\nPhysicsProcess and Process is disabled");
			return;
		}
		if (!IsInstanceValid(node))
		{
			SetPhysicsProcess(false);
			SetProcess(false);
			GD.PushWarning($"node in {Name} is not null but still is not valid\nPhysicsProcess and Process is disabled");
			return;
		}

	}
	public override void _Process(double delta)
	{
		GD.Print("Procesing");
	}
}

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