mastodon.gamedev.place is one of the many independent Mastodon servers you can use to participate in the fediverse.
Mastodon server focused on game development and related topics.

Server stats:

5.6K
active users

dbat :godot:

Godot 4 Question
----------------
Context: Writing an Addon in gdscript.
Aim: Create scripts at runtime & have class_name registered.

I need to make scripts like:
class_name Foo
extends Resource

and:
class Bar
extends Foo

Hence Foo and Bar must be 'known' by Godot.

I can make, write and new() the scripts but Godot does not recognize the class names.

Any ideas? Super stuck. 😔

@dbat Have you tried not defining class_name, using a relative path for extends and in your plugin.gd called add_custom_type ?

@phlowrient Hi. Thanks for the idea, but the scripts I am making are not 'part' of the actual addon, they will be in res://someplace and can't be preloaded.

I am actually trying to make a graph-node thing that lets me make classes and extend them.

My next thought is to use:
extends "path/somescript.gd"

😮 🦇

@dbat It looks like ScriptServer is not exposed to GDScript, so I doubt you can register global class at runtime. Those classes are stored in ProjectSetting and main.cpp reads them only once at initialization.
Do you need classes to be global? You could try `extends res://path` instead. Or keep a Dictionary of substitutions and replace a user typed class with a path at runtime.

@limbo Thanks Limbo. I have just started down that road. Thanks for the term "ScriptServer" - might help me to search in future.

🏆