How do I instantiate a C# script on a node without using a PackedScene?

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

I’m writing unit tests for my code and it would be useful if I could create an instance of the C# script I’m testing, which inherits from Node.

:bust_in_silhouette: Reply From: Atlinx

Ok it looks like you cannot use the “new” keyword to create a new C# node. This just makes an empty node for some reason. As a workaround for now, I’m getting the filepath to the C# script and using ResourceLoader.Load<CSharpScript>(filepath).New() to instantiate the script. This is basically equivalent to load(filepath).new() in GDScript.