Error get_tree: Condition "!data.tree" is true. Returned: nullptr

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By njamal816

Hello,

I am trying to call SilentWolf Plugin using C# and I am getting this error while trying to load highscore.

E 0:00:01.336   get_tree: Condition "!data.tree" is true. Returned: nullptr

<C++ Source> scene/main/node.h:269 @ get_tree()
Scores.gd:119 @ get_high_scores()

I am trying to call using the format below.

GDScript MySilentWolfScores = (GDScript) GD.Load("res://silent_wolf/Scores/Scores.gd");
		Object myGDScriptNode = (Godot.Object) MySilentWolfScores.New();

		myGDScriptNode.Call("get_high_scores");

These are the lines in Scores.gd.

func get_high_scores(maximum=10, ldboard_name="main", period_offset=0):
HighScores = HTTPRequest.new()
wrHighScores = weakref(HighScores)
if OS.get_name() != "HTML5":
	HighScores.set_use_threads(true)
get_tree().get_root().call_deferred("add_child",HighScores)
HighScores.connect("request_completed", self, "_on_GetHighScores_request_completed")
SWLogger.info("Calling SilentWolf backend to get scores...")
# resetting the latest_number value in case the first requests times out, we need to request the same amount of top scores in the retry
latest_max = maximum
var game_id = SilentWolf.config.game_id
var game_version = SilentWolf.config.game_version
var request_url = "https://api.silentwolf.com/get_top_scores/" + str(game_id) + "?version=" + str(game_version) + "&max=" + str(maximum)  + "&ldboard_name=" + str(ldboard_name) + "&period_offset=" + str(period_offset)
send_get_request(HighScores, request_url)
return self

Any help is appreciated. Thank you.

:bust_in_silhouette: Reply From: Zylann

I dont know this plugin at all, but what this error means is, you tried to call a function that wants to access the scene tree. The instance of Scores.gd script requires to be in the tree.

GDScript MySilentWolfScores = (GDScript) GD.Load("res://silent_wolf/Scores/Scores.gd");
Object myGDScriptNode = (Godot.Object) MySilentWolfScores.New();

myGDScriptNode.Call("get_high_scores");

Based on this code, you are not adding it to the tree. Besides, the node will never be cleaned up upon exit for the same reason.

Maybe you need to add it to the tree like that? (assuming your own script is a node present in the scene tree).

var MySilentWolfScores = (GDScript) GD.Load("res://silent_wolf/Scores/Scores.gd");
var myGDScriptNode = (Godot.Node) MySilentWolfScores.New();

AddChild(myGDScriptNode);
myGDScriptNode.Call("get_high_scores");

Can’t say further about how to use that plugin properly because it seems it has no public docs and requires signup.