Create Timer Giving Me "Parameter data.tree is null" error

Godot Version

4.2.2 Stable Official

Question

So, I’m making a project and everything has gone perfectly fine until now. Now whenever line 16(Or this line: await get_tree().create_timer(8).timeout;) gets called it gives me this error in the debugger for some reason. This all started after I added a new scene called “nightOneEnter” and made a line that goes to it. Which is this line: get_tree().change_scene_to_file(“res://nightOneEnter.tscn”);

extends Node2D

@export var fade : Node;
@export var newspaper : Node;

var A = false;

func _process(_delta):
if fade.modulate.a != 255:
for i in range(0, 100):
await get_tree().create_timer(0.01).timeout;

		fade.modulate.a -= 0.0001;

if A == false:
	await get_tree().create_timer(8).timeout;
	
	for i in range(0, 100):
		await get_tree().create_timer(3).timeout;
	
		fade.modulate.a += 0.1;

	await get_tree().create_timer(1).timeout;

	get_tree().change_scene_to_file("res://nightOneEnter.tscn");
	
	A = true;

func _on_change_scene_pressed():
print(“Button Pressed”);

for i in range(0, 100):
	await get_tree().create_timer(0.01).timeout;
	
	fade.modulate.a += 0.1;

get_tree().change_scene_to_file("res://nightOneEnter.tscn");

E 0:00:07:0352 newspaper.gd:16 @ _process(): Parameter “data.tree” is null.
<C++ Source> scene/main/node.h:413 @ get_tree()
newspaper.gd:16 @ _process()

The error message “Parameter ‘data.tree’ is null” indicates that the get_tree() function is returning null. This can happen if the node hasn’t been fully added to the scene tree when the function is called.

There are a few potential issues and improvements to address:

Ensure Node is in the Scene Tree: Use the _ready() function instead of _process() for initial setup. _ready() is called when the node is added to the scene tree, ensuring get_tree() is valid.

Correct Modulation Adjustment: The modulation adjustment loop may not work as expected because it’s nested inside _process(), which is called every frame.

Avoid Long Running Loops in _process(): Using await and long-running loops inside _process() can cause performance issues. Consider using timers or coroutines outside of _process().

extends Node2D

@export var darkness : Node;
@export var newspaper : Node;

func delay(time):
await get_tree().create_timer(time).timeout;

func fadeIn():
for i in range(0, 100):
await get_tree().create_timer(0.01).timeout;

	darkness.modulate.a -= 0.0001;

func fadeOut():
for i in range(0, 100):
await get_tree().create_timer(3).timeout;

	darkness.modulate.a += 0.1;

func _ready():
fadeIn();

await get_tree().create_timer(8).timeout;

fadeOut();

await get_tree().create_timer(1).timeout;

get_tree().change_scene_to_file("res://nightOneEnter.tscn");

func _on_change_scene_pressed():
print(“Button Pressed”);

for i in range(0, 100):
	await get_tree().create_timer(0.01).timeout;
	
	darkness.modulate.a += 0.1;

get_tree().change_scene_to_file("res://nightOneEnter.tscn");

Ok, I’ve made some changes to the code but now the fade in code doesn’t work. I’ve done a little debugging and found out the problem is that “darkness.modulate.a -= 0.0001;” doesn’t do anything.

why not a tween? or make use the AnimationPlayer node and it’s animation_finished signal.

func _on_change_scene_pressed():
    var tween := darkness.create_tween()
    tween.tween_property(darkness, "modulate:a", 1, 1).from(0)
    await tween.finished

    get_tree().change_scene_to_file("res://nightOneEnter.tscn")

Make sure to use the </> button on a new line when inserting code, it will create three back ticks like so.

```
type or paste code here
```

How do tweens work and what does that do?

Tweens are a way to define animations in scripts. This tween takes the modulate.a of darkness and over 1 second, starts from 0.0 and interpolates it to 1.0.

In this case I would recommend using an AnimationPlayer since tweens are more useful when you need to define the start and/or end point in scripts

I just realized I am stupid, it’s += instead of -= I’m really sorry

And now that that has been fixed, the error is back now, it now happens when the await get_tree().create_timer(0.01).timeout; in the fade out function is called for the 60th time. But now when that function waits 8 seconds in the ready function it doesn’t give the error. Also, when I tried the tweens it just instantly went from the first state to the other state.

I fixed the error.

Pls mark this as solved

For the tweens it might have read it as an int, try using decimal points even if superfluous

tween.tween_property(darkness, "modulate:a", 1.0, 1.0).from(0.0)

I would highly recommend getting tween or an AnimationPlayer to work, creating timers over and over, especially as sub-frame times is bad for performance and sets a maximum framerate for the effect.

1 Like