godotengine / godotengine/godot-cpp

How to initialize a custom class with parameters

Open
#293 0 comments 10 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

Hi there,

I wondered if it was possible to instantiate a custom GDNative class with arguments in GDNative code.
This could be useful in several situations e.g. :
1. class with const members which require a parametrized constructor with initialization list
2. inline-style instanciation like `some_function(some_class::_new(/* some arguments */));`

As far as I understand GDNative library, it seems a custom class `some_class` is intanciated by `NativeScript::new_()` itself called from the `some_class::_new()` function itself inserted by the `GODOT_CLASS()` macro.

However in this processus no argument is passed.

Anyone could tell me a bit more about how to use the C++ constructors and/or the `_init()` method to pass arguments upon instanciation ?

Best
Flarkk

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.