+10 votes

Hello, I have two objects in my scene (Some variables names are in French. Don't worry, it doesn't matter here ;) ).

  • Joueur, which is the player. Its script is "res://Joueur/joueur.gd"
extends RigidBody2D

export(String, "LOCAL", "NETWORK", "AI") var type = "LOCAL"
export var vit_marche_max = 1200
export var vit_marche_min = 100
export var force_marche_sol = 1000
export var force_marche_air = 250
export var force_arret_sol = 300
export var force_arret_air = 100
export var val_saut = 700
export var duree_saut = .3
  • Joueur 2 which is an AI. Its script is "res://Joueur/AI.gd" and it inherits from the fist one
extends "res://Joueur/joueur.gd"
 
export var decision_delay = 1.5
export var aggressivity = 3

Thus, the inspector shows that :
Inspector view
(Note that the type of Joueur 2 has been manually modified from "LOCAL" to "AI")

Here is my question: for Joueur 2, is it possible to separate the variables from the general script and the one from the inherited script?

There are subcategories for other elements, as the PhysicBody2D :
PhysicBody2D

What I would like is something like this :
ideal configuration

Do you know if this is possible ?
Thank you!

in Engine by (284 points)
edited by

BTW, I opened an issue about it: https://github.com/godotengine/godot/issues/4378

2 Answers

+13 votes
Best answer

It is possible, though it isn't easy. The basic idea is to override _get(), _set() and _get_property_list(). Also, since it has to run in the editor to display it, you need to use the tool keyword, and restart (at least in 2.0.2) every time you change that script's editor logic.

Here is a simple example:

tool
extends Node2D

var test = "" # We will store the value here

func _get(property):
    if property == "test/test":
        return test # One can implement custom getter logic here

func _set(property, value):
    if property == "test/test":
        test = value # One can implement custom setter logic here
        return true

func _get_property_list():
    return [
        {
            "hint": PROPERTY_HINT_NONE,
            "usage": PROPERTY_USAGE_DEFAULT,
            "name": "test/test",
            "type": TYPE_STRING
        }
    ]
by (1,590 points)
selected by

Thank you very much!
That works really well, I will now see how to adapt it to my code.

Can this be done in C#?
edit: yes!

override public Godot.Collections.Array _GetPropertyList(){
    var props = new Godot.Collections.Array(); 
    var enumstr =String.Join(",",Enum.GetValues(typeof(AiMovementType)));
    props.Add(PropEntry("HowToMove",Godot.Variant.Type.Int,Godot.PropertyHint.Enum,enumstr));
    return props;
}
public AiMovementType HowToMove;
public enum AiMovementType {XDir}
public static Godot.Collections.Dictionary PropEntry(string name,Godot.Variant.Type type, Godot.PropertyHint hint, string hintStr=""){
    var d = new Godot.Collections.Dictionary();
    d.Add("name",name);
    d.Add("type",type);
    d.Add("hint",hint);
    d.Add("hint_string",hintStr);
    return d;
}

And enums and such can be made by using PropertyHint

    //
    // Summary:
    //     Hints that an integer, float or string property is an enumerated value to pick
    //     in a list specified via a hint string such as "Hello,Something,Else".
    Enum = 3,
0 votes

This is not possible from the gdscript. It would be wise to create feature request on github page, since core developers are currently working on improving that kind of features (for plugin creation) and it's great moment for such request: https://github.com/godotengine/godot/issues
EDIT: actually it's possible, check Bojidar Marinov answer.

by (1,289 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.