Skip to content

Allow custom GDScript annotations which can be read at runtime #1316

@Wavesonics

Description

@Wavesonics

Describe the project you are working on:
Multiplayer game

Describe the problem or limitation you are having in your project:
Automaticly serializing custom data classes

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
In 4.0 GDScript now has annotations. What I propose is two fold:

  1. User's can declare their own custom annotations much like how Java allows you to (override a built in Annotation class)
  2. User's can query a classes properties and methods for their associated annotations at runtime

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

extends Reference
class_name MyDataClass

@Serialize(name="json_foo")
var foo: int

@Serialize
var bar: String

var x: Boolean

Then I can wrote some code to introspect MyDataClass and find it's properties that it wants serialized, and produce something like:

{
    "json_foo": 0,
    "bar": "test"
}

If this enhancement will not be used often, can it be worked around with a few lines of script?:
It can be worked around, it will just be less flexible and elegant.

Is there a reason why this should be core and not an add-on in the asset library?:
At least this particular approach would not be possible without support from GDScript it's self. But other approaches are possible, such as just listing all of the properties using the current inspection methods, and serializing all of them.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions