-
Notifications
You must be signed in to change notification settings - Fork 0
Macros reference
-
GCLASS
(class_name, base_class_name)
- register class -
GVIRTUAL_CLASS
(class_name, base_class_name)
- register virtual class -
GABSTRACT_CLASS
(class_name, base_class_name)
- register abstract class -
GINTERNAL_CLASS
(class_name, base_class_name)
- register internal class
Macro that you need to put at the BOTTOM[^1] of your class declaration to register class and use other macros.
class Example : public godot::Object {
// ...
GCLASS(Example, godot::Object);
};
-
GINIT_LEVEL_CORE
()
-
GINIT_LEVEL_SERVERS
()
-
GINIT_LEVEL_SCENE
()
-
GINIT_LEVEL_EDITOR
()
Register class at respective init level. Scene level by default. See godot::ModuleInitializationLevel
.
class Example : public godot::Object {
GINIT_LEVEL_CORE();
// ...
};
-
GSIGNAL
(signal_name, [[arg_type], arg_name], ...)
Register signal signal_name
with N arguments of type arg_type
or Variant
.
class Example : public godot::Object {
GSIGNAL(empty_signal);
GSIGNAL(example_signal, int typed_arg, untyped_arg);
// ...
};
-
GPROPERTY
(setter, getter [, property_hint] [, property_hint_string])
Register property with setter/getter, and optional property hint and property string. Incorrect property types will raise compiler error.
Optional property_name
expands to PROPERTY_HINT_<PROPERTY_NAME>
. See PropertyHint
enum in editor reference for possible type hints and for hint strings for each specific hint type.
Use Ref<ResourceType>
properties for reference-counted properties.
Resource types are given PROPERTY_HINT_RESOURCE_TYPE with correct hint_string
by default, override with none
property_hint.
class Example : public godot::Object {
GPROPERTY(set_float, get_float);
float float_prop;
// Slider from 0 to 1000 with step of 2
GPROPERTY(set_int, get_int,
range, "0,1000,2");
int int_prop;
// Will accept only AnimatedTexture
GPROPERTY(set_anim, get_anim);
Ref<AnimatedTexture> anim;
// Will accept any texture
GPROPERTY(set_anim_any, get_anim_any,
none);
Ref<Texture> anim_any;
};
-
GGROUP
(group_name)
-
GSUBGROUP
(subgroup_name)
Set group/subgroup name for all following registered properties. Place empty macro to reset group.GGROUP()
also resets previous subgroup
class Example : public godot::Object {
GGROUP(group);
GPROPERTY(set_float, get_float);
// group_float_prop;
float float_prop;
GSUBGROUP(subgroup);
GPROPERTY(set_int, get_int);
// group_subgroup_int_prop;
int int_prop;
GGROUP();
// vec_prop
Vector2 vec_prop;
};
GBITFIELD
()
Register next enum as a bitfield. You have to set proper flags by yourself.
class Example : public godot::Object {
// ...
public:
GBITFIELD();
enum Flags {
FLAG_ONE = 1,
FLAG_TWO = 2,
FLAG_THREE = 4,
};
};
GMETHOD
()
Register next method. Useful when auto-registering methods is disabled, or when you need to register private method. Compiler error will be raised if method signature is not supported.
class Example : public godot::Object {
// ...
GMETHOD();
void do_something();
};
GIGNORE
()
Ignore next method/enum/constant declaration.
class Example : public godot::Object {
// ...
GIGNORE();
int ignore_method();
GIGNORE();
enum ignore_enum {
ONE,
TWO,
};
GIGNORE();
enum {
IGNORE_CONSTANT = 42,
};
};
GVARARG
([[arg_type] arg_name], ...)
Register vararg method. Takes argument names list with optional types similar to GSIGNAL
.
Method signature must be void (const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error)
.
class Example : public godot::Object {
// ...
GVARARG(String named_arg, unnamed_arg);
Variant varargs_func_example(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error);
};
GRPC
([authority] [, reliable] [, call_local], [, channel])
Configure as RPC method with respective parameters. See Node::rpc_config
method and GDScript's @rpc
in-editor reference.
You need to call _rpc_config()
method on your node to enable configuration either in void _ready() override
method or on NOTIFICATION_READY
notification.
class Example : public godot::Object {
// ...
GRPC(authority, reliable, call_local);
void rpc_example(int p_value);
GRPC(any_peer, unreliable_ordered, call_remote, 42);
void rpc_example2();
};
[^1]: Technically, if you're not using auto-generated setters/getters, you can put it anywhere.