pragmagic / godot-nim

Nim bindings for Godot Engine
https://pragmagic.github.io/godot-nim/
Other
497 stars 27 forks source link

Error when accessing PhysicsDirectSpaceState #91

Closed alexpardes closed 3 years ago

alexpardes commented 3 years ago

Calling directSpaceState on World causes ERROR: : Nim constructor not found for class BulletPhysicsDirectSpaceState At: godotnim.nim:280 and returns nil.

Here is a simple project which reproduces this behavior when the window is clicked: https://github.com/alexpardes/godot-nim-stub I am using Windows 10, Godot 3.2.3, and Nim 1.4.2

endragor commented 3 years ago

This is a bug in Godot that it doesn't provide this class in api.json for some reason. The workaround is to add this to your main Nim module:

import godot, godotapi/godottypes

type
  BulletPhysicsDirectSpaceState* = ref object of PhysicsDirectSpaceState
registerClass(BulletPhysicsDirectSpaceState, cstring"BulletPhysicsDirectSpaceState", true)
alexpardes commented 3 years ago

Thank you. That workaround resolves the issue for me.

I am curious why it is a bug for Godot not to export information about a subclass which (I assume) is only intended to be used through reference to its base class (PhysicsDirectSpaceState3D/PhysicsDirectSpaceState). Why is knowing about BulletPhysicsDirectSpaceState necessary for godot-nim?

endragor commented 3 years ago

When you call directSpaceState, it returns an instance of BulletPhysicsDirectSpaceState. To be able to construct it, Nim side needs to know about the class. It doesn't matter how it's intended to be used.