Skip to content

How to instantiate custom class via GDNative (Question) #253

Closed

Description

@xDGameStudios

What is the correct way to instantiate a custom class and return it to Godot via GDNative?!

(minimal representation below)

class A : public Reference {
     Ref<B> create_b()
}

class B : public Reference {
}

what should be the body of create_b() ?
for future reference the correct way to do this is:

return Ref<B>::__internal_constructor(B::_new()) ;)

Activity

  1. changed the title [-]How to instantiate custom class via GDNative [/-] [+]How to instantiate custom class via GDNative (Question)[/+] on Mar 29, 2019
  2. follower commented on Jun 22, 2020

    @follower

    As of ~ 9eceb16 the __internal_constructor() workaround should no longer be necessary and use of it may lead to crash, this should now work correctly:

    • Ref<CustomClass> ref = Ref<CustomClass>(custom_class_instance);

    See #417 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions