Is it possible to create a new object without knowing it's class_name until runtime?

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

I’m trying to instance an object in code.

Normally, I would use ClassName.new(), except in my case, I’m loading the class name from a string variable.

e.g.

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 get_property_list of that class type… is there a better way to do that?

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.

Inces | 2022-01-27 21:03

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

rossunger | 2022-01-27 21:18

:bust_in_silhouette: Reply From: rossunger

ClassDB.instance() is the correct answer

Thank you Inces