pragmagic/godot-nim

Error when accessing PhysicsDirectSpaceState

alexpardes opened this issue · 3 comments

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

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)

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?

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.