Improving InstancePlaceholders #5128
Replies: 2 comments 5 replies
-
Absolutely not! These are all great ideas. As Godot can be used for creating increasingly bigger games, there will be an increasing necessity to load things dynamically while still being able to manage and edit them as one. InstancePlaceholders can be used for that kind of thing, too, and if large games are bound to be made, improving them during 4.x should probably be high up there. Speaking of which, it does bother me there's no simple way to load the Node InstancePlaceholders are taking the place of in between frames, without locking the main thread. It is possible, but it requires another Script and a bit of grease and elbow. If InstancePlaceholders could have their own properties, a setting to allow this would certainly be welcome. |
Beta Was this translation helpful? Give feedback.
-
Hey, this looks really useful. Got an idea! What about have another type called It would have a property that could be either a Used just like any other node that can be in a node hierarchy, its node children would be Nodes/Scenes that aren't instanced yet, but just lay there on "stand-by". It would work just like a substitute until the instances are created (holding the values (game state) of the desired properties of the specified instances). Its role would be kind of a placeholder / factory / spawner / arranger / proxy. Some use cases for
Also after instancing, can choose between:
|
Beta Was this translation helpful? Give feedback.
-
Introduction
InstancePlaceholders are a powerful tool to create dynamic levels that don't need to load everything at once. The major benefit to them over creating factories or various other loaders is that they retain the editability of a regular child scene; exported properties remain visible and are automatically set to the instanced child scene when created. Despite their general usefulness, InstancePlaceholders see very little attention. That can be traced back to the lack of tutorials and less-than-ideal implementation. This is a discussion about improving the latter, but before delving into the issues it's best to recap how InstancePlaceholders can be used:
InstancePlaceholders are deceptively simple to use. Deceptively, because they have many undocumented quirks to them; some bordering the line between a bug and implementation detail. The following is a short list of either unclear details or general considerations about their current implementation and how they could be improved. This is a very open-ended proposal. Any suggestions, thoughts, alternatives etc. are most welcome. Without further ado:
Issues
1. Undo/redo
Related: godotengine/godot#62727.
Toggling "Load As Placeholder" should be saved to undo history despite it currently being a rather undestructive operation (still alters the scene file).
2. Child nodes
(Nodes added under child scenes)
Current:
When the scene is loaded as a placeholder, the nodes will be children of the created InstancePlaceholder. When the placeholder is "replaced" its children will be freed alongside it. This is only expected if the user intended the nodes to be children of the placeholder node, but this is unclear within the editor.
Alternative 1. (Simple)
Document current behaviour (preferably with an example).
Alternative 2. (Simple)
Change behaviour
Alternative 3. (Simple)
Clarify behaviour by bringing back deprecated
replace_by_instance()
and remove parameterreplace
fromcreate_instance()
3. Function naming*
*Written before merging the updated documentation; Could be considered solved.
Related: godotengine/godot#64127
Current
The function
create_instance()
is a little misleading as it doesn't imply that the instance will also be added to the scene. It is also unclear where it is added in relation to the InstancePlaceholder.Alternative 1. (Simple)
Retain current behaviour, but document how the function operates.
Alternative 2. (Simple)
Bring back deprecated
replace_by_instance()
and changecreate_instance()
to only create and return the instance making it possible to manually choose where the instance will be added:4. Groups and signals
Related: godotengine/godot#18697.
Related: godotengine/godot#64238.
Current
Currently, groups and signals set in the editor are assigned to the InstancePlaceholder instead of the child scene root. This is undocumented and there are no indications of this happening inside the editor.
Alternative 1 (Simple)
Retain current editor behaviour, but document it and raise a configuration warning when a signal is tried to connect to or from the child scene. Also don't connect the signals to the InstancePlaceholder.
Alternative 2 (Complex)
Have InstancePlaceholder save connections from and to it and try to assign them during replacement (this might be complicated to do on the engine side and may lead to other unexpected behaviour) and also save the group inside InstancePlaceholder and assign it to the replacement (likely optionally similar to replace_by()).
Alternative 3 (Simple)
Combination of 1 and 2. Raise warning for signals but (optionally) save and assign groups to the replacement.
5. Exported properties
Current
Similar to signals and groups, InstancePlaceholder "steals" all properties saved to the scene it can. This leads to the funky behaviour where overridden properties of node and object are attached to the InstancePlaceholder (such as process_priority and script) instead of the child scene. Properties not found in those classes work "as expected", and are stored inside
stored_values
in InstancePlaceholder. The current behaviour is borderline a bug and should probably be changed.Alternative 1 (Simple)
Pass the changed property values to the replacement, instead of stealing them.
Alternative 2 (Complex but flexible)
Make the properties of InstancePlaceholder editable inside the Inspector.
Examples: Image1 Or: Image2
6. Extending
Current
Currently, InstancePlaceholder isn't exposed fully. It is not possible to extend InstancePlaceholder even though it is possible to add a script to it at runtime. This means users can only attach scripts that extend Node to it. Similarly, it is not possible to add InstancePlaceholder-node to a scene inside the editor. However, it is possible to save a scene that has InstancePlaceholders result.
Alternative 1 (Simple, flexible)
Expose InstancePlaceholder to be used as a node and extended and when packing a scene save InstancePlaceholder nodes optionally as placeholders instead of nodes of type InstancePlaceholder.
Alternative 2 (Simple, restrictive)
Don't expose and when packing a scene, save InstancePlaceholders nodes as placeholders instead of nodes of type InstancePlaceholder.
Missing features
This is a list of features that would generally improve InstancePlaceholders but are not as crucial to solve as the issues mentioned before.
Function to convert nodes/scenes to InstancePlaceholders or create them at runtime. (They're only created when PackedScene is instantiated)I stand corrected. It is actually trivial to create them exactly by packing a scene:create_instance()
)End
Thank you for coming to my TED talk. Once again I'm asking for your wiser opinions, suggestions and feedback. Does anyone even care? Should InstancePlaceholders be deprecated altogether? Let yourself be known.
Beta Was this translation helpful? Give feedback.
All reactions