touilleMan / godot-python

Python support for Godot 🐍🐍🐍
Other
1.87k stars 140 forks source link

Cannot instance Reference derived class using NativeScript resource. #276

Open dluke opened 3 years ago

dluke commented 3 years ago

Having defined a Reference derived type and loaded the NativeScript resource, when using .new() godot-python tells me Refcounted Godot object must be created with NativeScript() Indicating that the correct syntax is to call the class name i.e. Array() but then TypeError: 'godot.bindings.NativeScript' object is not callable that doesn't work either.

Is this a bug or am I doing it wrong?

touilleMan commented 3 years ago

Hi @dluke !

Godot classes are not all refcounted, this is strange from a Python point of view where everything is supposed to be garbage collected.

So in Godot-Python you instantiate refcounted Godot classes with the traditional MyClass() and non-refcounted ones with MyClass.new() that makes explicit you are now responsible for freeing this object.

Regarding your NativeScript issue, I'm able to instantiate a NativeScript object by doing:

def test_instantiate_nativescript():
    from godot import NativeScript
    x = NativeScript()

Can you provide more informations to reproduce the issue ?