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

Save non exported variables in PackedScenes #761

Open
Shadowblitz16 opened this issue Apr 28, 2020 · 4 comments
Open

Save non exported variables in PackedScenes #761

Shadowblitz16 opened this issue Apr 28, 2020 · 4 comments

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented Apr 28, 2020

Describe the project you are working on:
A 3D Tower defense game that requires saving a node with a grid

Describe the problem or limitation you are having in your project:
current gridmaps only work for meshes so made my own grid class (not node) and tried to save a node with a reference to it at runtime as a packed scene.

to my surprise I found out godot doesn't support saving variables in packed scenes unless they are exported and custom classes can't be exported.

this forces developers to export everything even if they want to have it hidden.
which in this case isn't even possible.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
I suggest that all variables/properties are saved in packed scenes or at least give us a way to mark them as serializable

this allows people like myself to save custom classes in packed scenes without resorting to json and not having to export them later when its supported

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
either allow us to use a serializable keyword or just save the entire scene and its state including its non exported variables

If this enhancement will not be used often, can it be worked around with a few lines of script?:
right now data oriented design is horrible in godot and we can't do much at all without making everything a node. this would be used everytime someone saved a packed scene
and i don't know of a way to work around this. but let me know if you do.

Is there a reason why this should be core and not an add-on in the asset library?:
because we shouldn't have to have everything as a node in godot and currently like I said data oriented design is horrible in godot

@Xrayez
Copy link
Contributor

Xrayez commented Apr 29, 2020

custom classes can't be exported

If I understand you correctly, yeah it's not possible to export a specific resource type, but you can export a generic resource (to which you can pass your custom one):

export(Resource) var custom_resource

give us a way to mark them as serializable

I've experimented a bit, and figured it's actually quite possible to make existing properties "exportable" while having them hidden in the editor, but requires low-level API:

tool
extends Node2D

var member = 10

func _get_property_list():
	var serializable = [
		{
			name = "member",
			usage = PROPERTY_USAGE_NOEDITOR,
			type = TYPE_INT,
		}
	]
	return serializable

If you save this script with the scene and look at the contents of the tscn file, you'll notice that member will be there, but won't be visible in the editor (just like you want it I suppose).

PROPERTY_USAGE_NOEDITOR combines both PROPERTY_USAGE_STORAGE and PROPERTY_USAGE_NETWORK.

This could probably be added to GDScript exports page (once we get to merge godotengine/godot-docs#3444 😛). I'm not sure if this hacky enough, because you can expose the same member twice with export(int) var member and exporting the same member with PROPERTY_USAGE_EDITOR for instance, might be just a UI bug:

Annotation 2020-04-29 034136

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Apr 30, 2020

see things like this need to be supported better.
why can't we have a serialize keyword that does this for us?
I don't want to have a bunch of

	var serializable = [
		{
			name = "member",
			usage = PROPERTY_USAGE_NOEDITOR,
			type = TYPE_INT,
		}
	]

everywhere

serialization and exposing it to the inspector should NOT be the same thing.
edit: there seems to be something simular to C# attributes being discussed maybe that would work.

@Xrayez
Copy link
Contributor

Xrayez commented May 1, 2020

Yeah, I hope that many of the not-so-common hidden features could be made available via GDScript annotations, at least to some extent: godotengine/godot#20318.

@Xrayez
Copy link
Contributor

Xrayez commented May 1, 2020

Related discussion: godotengine/godot#5988.

Specifically the suggestion to use @export and @serialize annotations in godotengine/godot#5988 (comment).

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

3 participants