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

SubClass as Custom types for export #3597

Closed
LeonardMeagher2 opened this issue Feb 5, 2016 · 11 comments
Closed

SubClass as Custom types for export #3597

LeonardMeagher2 opened this issue Feb 5, 2016 · 11 comments

Comments

@LeonardMeagher2
Copy link
Contributor

It'd be nice to be able to export a SubClass as a type of export and if you'd go into it and the exported variables from it would be accessible in the editor.

Related, #3586, is requesting Typed Arrays from gdscript, which I'd also like to see SubClasses show up there.

class a():
    export var b = 0
    func _init(in):
        b = in

export(a) var custom_export
# export(array,a) var custom_export_array

@vnen vnen changed the title SubClass as Custom types for export [Feature Request] SubClass as Custom types for export Feb 6, 2016
@Zylann
Copy link
Contributor

Zylann commented Aug 7, 2016

I agree, I'm currently unable to encapsulate data from an exported variable because I cannot make it a class.
This is what I have, as typical example:

tool
extends Node

const Grid = preload("addons/terrain/array2d.gd")

# Error: export hint is not a type or resource
export(Grid) var save = null

func _ready():
    save = Grid.create(8,5,1)

Godot complains the type is not a resource, but mine actually inherit Resource. And anyways, I don't necessarily want it to be a Resource.
So everywhere in my code, I use an array of arrays with C-like helpers...

@vnen
Copy link
Member

vnen commented Aug 7, 2016

There's a bit of a problem here: how will the inspector know how to handle the export? For built-in types there's code to handle each type and for resources there's the ResourceLoader to know which file types can have the resource.

This should work with custom resources made by plugins (maybe it already does, as I haven't tested).

@Zylann
Copy link
Contributor

Zylann commented Aug 7, 2016

Well, in my case the problem actually resides in saving, not in displaying the class in the inspector. If the inspector has no editor for that, it should simply ignore it or display nothing (like Dictionaries), thought a bit of reflection could help making a generic editor.
The fact that saved variables must be either an engine type or a resource is weird, there is no in-between, and it impacts the whole codebase behind it.

@vnen
Copy link
Member

vnen commented Aug 7, 2016

It's not "weird", it's just the way it was designed. Of course it can be improved and it's mostly matter of how (hence my previous questioning). So far everybody lived with it this way.

I don't like the idea of making export ignore custom types, since it's not what the user would expect and it would be frustrating.

Also, don't think there's a default serialization for generic objects. That's another issue, but it would be required to save any kind of object in a PackedScene resource file.

@bojidar-bg
Copy link
Contributor

Well, we can have subclasses export variables as well, can't we?

@williamd1k0
Copy link
Contributor

@vnen This should work with custom resources made by plugins (maybe it already does, as I haven't tested).

I don't know about plugins but it's not working for simple custom resources.
I'm interested in this feature because of the new class_name keyword.

Now you can create a custom resource and expose it globally but you can't export it by its type, only using the Resource type.

Example

  • Creating a custom resource:
extends Resource
class_name CustomResource, "optional-icon.png" # 3.1

export(String) var some_data

  • Trying to export it (3.1):
extends Node

export(CustomResource) var custom_res

This will show the following error: Parse Error: Expected a constant expression.


  • Trying to export it pre-loading the script:
extends Node

const CustomResource = preload('res://CustomResource.gd')
export(CustomResource) var custom_res

This will show the following error: Parse Error: Export hint not a resource type.


This issue is a bit old but exporting custom resources would be really useful for 3.1.

@twheys
Copy link

twheys commented Apr 12, 2019

Would love to see this feature added. I imagine if the exported class is though of as a collection of types the Editor knows how to handle, I don't see why it couldn't behave the same way properties are set on built-in complex types in the Inspector.

For example, a Spatial is shown in the editor as a list of Transform, Matrix, and Visibility, each which can be expanded and have their own set of attributes. I would love to be able to create my own settings like this.

Ultimately, I believe it should be entirely feasible to generalize the Inspector so a tree structure can be used.

spatial

@bojidar-bg
Copy link
Contributor

@twheys That would be #4378, since Transform, Matrix, and Visibility are not actual objects.

@Shadowblitz16

This comment has been minimized.

@Calinou
Copy link
Member

Calinou commented Jan 20, 2020

@Shadowblitz16 Please don't bump issues without contributing significant new information; use the 👍 reaction button on the first post instead.

@akien-mga
Copy link
Member

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

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

9 participants