0 votes

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.

in Engine by (29 points)

1 Answer

0 votes

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.

by (29 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.