gdext icon indicating copy to clipboard operation
gdext copied to clipboard

Classes at wrong init level

Open lilizoey opened this issue 1 year ago • 2 comments

PhysicsServer2D/3D and their related classes should be at Server.

Sometimes one would want to inherit from Object but have a class available before Scene. Could Object have its init level just be Core/Server or something?

lilizoey avatar Sep 09 '23 22:09 lilizoey

PhysicsServer2D/3D and their related classes should be at Server.

Ah yeah, the great heuristic "ends in 'Server'" because GDExtension doesn't expose the init level 😁

Could Object have its init level just be Core/Server or something?

Since other classes inherit from Object and are loaded earlier, that implies that Object itself should also be available at that time, so probably yes?

Are there other such classes (RefCounted or Resource) which are available earlier?

However, if we allow different init levels for user-defined classes, we may need to consider that "assume base class' init level" may not be desired. It wouldn't matter if no custom registration logic is run, but as soon as we have builders and user-defined register_class() overrides, it's possible that the user expects Scene level unless specified otherwise.

Bromeon avatar Sep 10 '23 12:09 Bromeon

However, if we allow different init levels for user-defined classes, we may need to consider that "assume base class' init level" may not be desired. It wouldn't matter if no custom registration logic is run, but as soon as we have builders and user-defined register_class() overrides, it's possible that the user expects Scene level unless specified otherwise.

Maybe we should have everything get registered at Scene by default, unless the base class uses Editor. And allow the user to specify the level manually if they want earlier. Failing (ideally at compile time but maybe only runtime is feasible?) if they try to register it earlier than the base class.

lilizoey avatar Sep 10 '23 14:09 lilizoey

Fixed by https://github.com/godot-rust/gdext/pull/680.

Bromeon avatar Jun 12 '24 18:06 Bromeon