Static Scenes #7571
Closed
nlupugla
started this conversation in
Engine Core
Static Scenes
#7571
Replies: 1 comment
-
It was recommended that I move this discussion to an issue. Please see #7572 if you would like to share your thoughts. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
It would be great if there was a way to tell the engine that certain aspects of a scene's tree will never change. This could provide many advantages, such as node type safety, better editor autocompletion, and potentially performance improvements.
Consider a simple example of a Character scene laid out as
It's easy to imagine that you would want all Character instances to have a valid Sprite of type Sprite2D and valid HealthBar of type ProgressBar. Currently, the engine provides no built-in way to enforce such a constraint; there's nothing preventing you from instancing a Character scene, then deleting/renaming/moving/replacing the Sprite or ProgressBar node. This lack of constraint has a few important consequences:
$Sprite
is not cached for fast lookup (see Make the $ operator in GDScript cache node references (or add a $$ operator) #996)$Sprite
is typed as aNode
, notSprite2D
.Sprite
somewhere in code, the engine can only warn you about this at runtime when you try to access$Sprite
and the node isn't found.This static scene proposal aims to solve all of the above issues.
Here's how this might look in practice. In the editor, there is a way to mark a node as "static". This could be a checkbox near where the "Access as Scene Unique Node" option appears. Checking this option makes that node, and all of its children, "static", meaning they cannot be deleted/renamed/moved/replaced, although they can still acquire new children. A script can then take advantage of this property by declaring the node as static in some way.
For example
Such a script will only be valid if a "static" node exists in the file "res://character.tsn" at path "^Character". In addition, the editor will highlight as an error any line that attempts to delete/rename/move/replace
Sprite
orHealthBar
.In summary, there are many cases where the engine user knows that certain parts of the scene tree are fixed. This proposal gives the user a way to inform the engine and benefit from that information. I would love to hear thoughts from the community on this idea!
Beta Was this translation helpful? Give feedback.
All reactions