This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm trying to instance an object in code.

Normally, I would use, except in my case, I'm loading the class name from a string variable.


var MyClassName = "ColorRect"
var newObject = str2var(MyClassName).new

should create a new ColorRect and store it in newObject.

Is there any way to instance an object without knowing it's class_name until runtime?

Ultimately, all I need to do is getpropertylist of that class type... is there a better way to do that?

Godot version 3.4.2
in Engine by (1,346 points)

I never tried it, but I found instance(string) method of ClassDB in documentation. check out if ot works. ClassDB also has a method class_get_property_list with string as argument, so You won't even have to create any new instance.

Thank you!!! this is exactly what I was looking for.

1 Answer

0 votes

ClassDB.instance() is the correct answer

Thank you Inces

by (1,346 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 Frequently asked questions and 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 [email protected] with your username.