Skip to content

How to initialize a custom class with parameters #293

@Flarkk

Description

@Flarkk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis is an enhancement on the current functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions