You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm developing a game in Godot where managing object instantiation and initialization is crucial for maintaining a clear and efficient codebase.
Describe the problem or limitation you are having in your project
Currently, when using PackedScene in Godot to instantiate objects, there is no direct way to pass parameters to the constructor (_init) of the instantiated scene. This limitation forces developers to use workarounds such as creating separate init methods without underscores, which deviates from standard practices and leads to confusion in the codebase.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I propose enhancing the instanciate method of PackedScene in Godot to allow passing parameters directly to the constructor (_init) of the instantiated scene. This enhancement would streamline object initialization by enabling developers to initialize scenes with specific parameters during instantiation, promoting cleaner and more intuitive code practices.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Here's a basic outline of how the proposed enhancement could work:
Enhance the instanciate method to accept parameters:
# Example pseudo-code
var parameters = {
"param1": value1,
"param2": value2
}
var instance = packed_scene.instanciate(parameters)
Allow passing parameters to the _init constructor of the instantiated scene:
# Inside the scene scriptfunc_init(param1, param2):
# Initialize the scene with the provided parametersself.param1=param1self.param2=param2
Benefits of allowing parameters in instanciate:
Enables cleaner and more maintainable code by adhering to standard initialization practices.
Reduces the need for separate initialization methods (init without underscores), minimizing confusion in the codebase.
Facilitates clearer understanding of scene initialization logic at the point of instantiation.
If this enhancement will not be used often, can it be worked around with a few lines of script?
Currently, developers can work around this limitation by manually setting properties after instantiation or by using separate initialization methods. However, these workarounds can lead to less efficient code and introduce unnecessary complexity, especially in projects with complex object hierarchies.
Is there a reason why this should be core and not an add-on in the asset library?
The ability to pass parameters to the _init constructor of scenes directly during instantiation is a fundamental feature that aligns with best practices in object-oriented programming. Implementing it as a core feature in Godot would improve developer productivity, maintainability, and code clarity across projects. It would also ensure consistent behavior and integration with the existing scene management system within the Godot engine.
The text was updated successfully, but these errors were encountered:
AThousandShips
changed the title
Enhancement Request: Allow Parameters in instanciate Method of PackedScene in Godot
Allow Parameters in instanciate Method of PackedScene in Godot
Jul 4, 2024
Describe the project you are working on
I'm developing a game in Godot where managing object instantiation and initialization is crucial for maintaining a clear and efficient codebase.
Describe the problem or limitation you are having in your project
Currently, when using PackedScene in Godot to instantiate objects, there is no direct way to pass parameters to the constructor (_init) of the instantiated scene. This limitation forces developers to use workarounds such as creating separate init methods without underscores, which deviates from standard practices and leads to confusion in the codebase.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I propose enhancing the instanciate method of PackedScene in Godot to allow passing parameters directly to the constructor (_init) of the instantiated scene. This enhancement would streamline object initialization by enabling developers to initialize scenes with specific parameters during instantiation, promoting cleaner and more intuitive code practices.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Here's a basic outline of how the proposed enhancement could work:
Allow passing parameters to the _init constructor of the instantiated scene:
Benefits of allowing parameters in instanciate:
If this enhancement will not be used often, can it be worked around with a few lines of script?
Currently, developers can work around this limitation by manually setting properties after instantiation or by using separate initialization methods. However, these workarounds can lead to less efficient code and introduce unnecessary complexity, especially in projects with complex object hierarchies.
Is there a reason why this should be core and not an add-on in the asset library?
The ability to pass parameters to the _init constructor of scenes directly during instantiation is a fundamental feature that aligns with best practices in object-oriented programming. Implementing it as a core feature in Godot would improve developer productivity, maintainability, and code clarity across projects. It would also ensure consistent behavior and integration with the existing scene management system within the Godot engine.
The text was updated successfully, but these errors were encountered: