Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow us to strongly type packed scenes #782

Open
Shadowblitz16 opened this issue May 2, 2020 · 9 comments
Open

Allow us to strongly type packed scenes #782

Shadowblitz16 opened this issue May 2, 2020 · 9 comments

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented May 2, 2020

Describe the project you are working on:
3d Tower defense

Describe the problem or limitation you are having in your project:
there is no way to strongly type packed scenes

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
can we have a some sort of generics for packed scenes that allow for strongly typed instancing

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
something like..

var scene : PackedScene(Spatial)

exporting generic packed scenes would also insure type safety in the inspector

If this enhancement will not be used often, can it be worked around with a few lines of script?:
it would be used alot and no not safely

Is there a reason why this should be core and not an add-on in the asset library?:
supports better code

@Jummit
Copy link

Jummit commented May 2, 2020

I actually get autocompletion for packed scenes, so I think this isn't needed. If you are programmatically loading PackedScenes, you can always define the type after instancing it.

@Shadowblitz16
Copy link
Author

autocompletion has nothing to do with this problem it has to do with type safety

@Jummit
Copy link

Jummit commented May 3, 2020

autocompletion has nothing to do with this problem it has to do with type safety

Ah, gotcha. That is something I didn't think about.

@Shadowblitz16
Copy link
Author

using this suggestion #1207
it would be something like this..

var scene : PackedScene<Spatial>

@Shadowblitz16
Copy link
Author

closing in favor of..
#2699

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented May 8, 2021

reopening due to people might needing to export packed scenes only instead of both packed scenes and nodes

@Shadowblitz16 Shadowblitz16 reopened this May 8, 2021
@Shadowblitz16
Copy link
Author

This might be better as...

@export var scene_or_node_path : Control

This we can drag in a scene or a node as long as it's that type.
Unity does this and it's really nice.

@salmelo
Copy link

salmelo commented Oct 1, 2023

I'd love to see this feature, coming from a unity background, but I'd really prefer if scenes and nodes inside scenes didn't both fit in the same variable. I can't think of any situation where you'd actually want a variable that could be either one, you'll have references to other nodes in the scene you're in and you'll have references to scenes you want to instantiate at runtime, but not both in the same box.

@DaloLorn
Copy link

DaloLorn commented Oct 8, 2023

If #1935 was implemented, then you actually could treat a node class as equivalent to its bound scene (if any) at runtime, since instantiating the node would automatically instantiate the scene. This would then permit us to extend that equivalence to the editor, offering the corresponding type safety and autocompletion improvements.

You could, admittedly, not expect that a PackedScene[Spatial] was a Spatial (since it only needs to have a Spatial as its root node), but you could expect that a Spatial is a PackedScene[Spatial] (because it can't not have a fully-functioning Spatial as its root node). I'm not sure if that explanation makes any sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants