Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | nwgdusr999 |
I’m trying to find out how you should instantiate an object containing variables? For instance, I tried;
MyObject.gd (script)
extends Reference
var var1
var var2
And then, in another script:
var MyObject= preload("res://scripts/MyObject.gd");
var myObjectInstance = MyObject.new();
But this results in a “Invalid call. Nonexistent function ‘new’ in base ‘Nil’.” I’m guessing that it’s because I’m trying to instantiate a script and not an object… So how should I go about creating an instance of the above object? It’s not a node that needs to be added to a scene, just an item to be used programmatically. Thanks!