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
Describe the problem or limitation you are having in your project
Coming from a Unity background, I am used to being able to assign a Prefab of a certain Type
e.g. I could export a Player on my PlayerSpawner and it would only accept prefabs that have the Player component attached.
As Godot's 'replacement' for Prefabs is Scenes, I would like to see something similar possible with scenes.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Right now, if I have a PlayerSpawner, and expose a Player with export, I can only select already existing instances of Player in the inspector.
I would like to also be able to select scenes that have the class_name Player script attached to their root node.
Right now, I can either:
refer to the player 'prefab' scene by path: This is pretty bad given now it relies on a hardcoded path.
@export var player_scene: PackedScene: With this, we can select ANY scene, even things that are not a Player, like a Door. So, we end up having to do a cast on instantiating the node, to verify that we are indeed spawning a Player.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Since Node only allows one gdscript to be attached, and a Scene always has a Root node, I would imagine it would be possible to restrict the Inspector to only select scenes that have the Player script attached to their root node.
e.g. return a list of scenes for the inspector that are filtered by something like this (pseudocode):
func is_scene_selectable(scene: PackedScene):
return true if scene.attached_script? is player else false
If this enhancement will not be used often, can it be worked around with a few lines of script?
Yes, for example, each time you instantiate a scene, you check it's type, but since this is something that happens often, it results into more and more lines of code.
Is there a reason why this should be core and not an add-on in the asset library?
Since it would also assume that you don't need to cast the player scene node to a Player.
The text was updated successfully, but these errors were encountered:
* [Allow us to strongly type packed scenes #782](https://github.com/godotengine/godot-proposals/issues/782)
* [Allow type specification of root node for exported PackedScenes #5255](https://github.com/godotengine/godot-proposals/issues/5255)
* [Add a generic parameter to PackedScene (like Array) to allow for easier type safety #6694](https://github.com/godotengine/godot-proposals/issues/6694)
Thanks, I did some digging but I couldn't find these issues at the time of posting
Describe the project you are working on
A little 2d top-down strategy game.
Describe the problem or limitation you are having in your project
Coming from a Unity background, I am used to being able to assign a
Prefab
of a certainType
e.g. I could export a
Player
on myPlayerSpawner
and it would only accept prefabs that have thePlayer
component attached.As Godot's 'replacement' for Prefabs is Scenes, I would like to see something similar possible with scenes.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Right now, if I have a
PlayerSpawner
, and expose aPlayer
withexport
, I can only select already existing instances ofPlayer
in the inspector.I would like to also be able to select scenes that have the
class_name Player
script attached to their root node.Right now, I can either:
@export var player_scene: PackedScene
: With this, we can select ANY scene, even things that are not aPlayer
, like aDoor
. So, we end up having to do a cast on instantiating the node, to verify that we are indeed spawning aPlayer
.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Since
Node
only allows onegdscript
to be attached, and aScene
always has aRoot
node, I would imagine it would be possible to restrict the Inspector to only select scenes that have thePlayer
script attached to their root node.e.g. return a list of scenes for the inspector that are filtered by something like this (pseudocode):
If this enhancement will not be used often, can it be worked around with a few lines of script?
Yes, for example, each time you instantiate a scene, you check it's type, but since this is something that happens often, it results into more and more lines of code.
Is there a reason why this should be core and not an add-on in the asset library?
Since it would also assume that you don't need to cast the player scene node to a Player.
The text was updated successfully, but these errors were encountered: