Ergonomics of instantiating PackedScene #296
Labels
c: engine
Godot classes (nodes, resources, ...)
quality-of-life
No new functionality, but improves ergonomics/internals
Problem:
The current ergonomics of PackedScene are really unwieldy to the typical user.
Take for example a basic custom element that needs extra initialization before being added to a scene.
No problems yet. But now I want to call the create method directly after instantiating the tile and then finally add it to the parent/self:
The main issue here, I have 3 steps to take before I can even get access to the create method I want. (Excluding the instantiate itself)
instantiate() -> unwrap/expect/whatever you prefer -> cast -> bind_mut() -> finally I can call my create method
3 steps aren't impossible, but there's also some "magic" sprinkled in of you know it or you don't that isn't present in GDScript's basic instantiate. (GenEditState::GEN_EDIT_STATE_DISABLED is the magic word, and is a mouthful)
Suggested Solution:
I brought this up on the discord and lIlIZ was really helpful and had a wonderful suggestion for an update to help ease usability.
Expose an instantiate_as() or try_instantiate_as()
It could look like:
With a usage like:
This would lessen the api for a typical user and make adoption of godot-rust that much easier. I'm especially a fan of the Option. Being able to pass None makes it about as close as you can get to the native GDScript feel.
The text was updated successfully, but these errors were encountered: