0 votes

Does anyone know how I do this from a c++ module for Godot 4?

@export var typed_test:Array[State]

When I code this in gdscript I get Typed Array in the inspector asking for the State resource (State is a custom resource created in my module)

This is what I have so far in my c++ module

TypedArray<State> states = TypedArray<State>();

in the .cpp:

void WorldStateManager::set_states(TypedArray<State> p_states) {
    states = p_states;
}

TypedArray<State> WorldStateManager::get_states() const {
    return states;
}

binding_methods:

ClassDB::bind_method(D_METHOD("set_states", "states"), &WorldStateManager::set_states);
ClassDB::bind_method("get_states", &WorldStateManager::get_states);

ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "states", PROPERTY_HINT_ARRAY_TYPE, "State"), "set_states", "get_states");

But in the inspector I get a normal Array and it doesn't ask for the State resource.

Godot version godot 4 alpha 12 (developing a module in c++)
in Engine by (198 points)

1 Answer

0 votes
Best answer

Oh found my answer by looking at how it's done in core/input/shortcut.cpp
The correct ADD_PROPERTY is as follows:

ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "states", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "State")), "set_states", "get_states");

And instead of TypedArray it's just Array

by (198 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 Frequently asked questions and 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 [email protected] with your username.