0 votes

Hi There!

I'm trying to create a skeleton from GDScript. Here is the full code, it creates a Mesh and a Skeleton with two PhysicalBones:

extends EditorScript

func add_collision(bone: PhysicalBone):
    var collision = CollisionShape.new()
    collision.shape = SphereShape.new()

func add_bone(skel: Skeleton, bone_name: String, parent_idx: int = -1):
    var bone = PhysicalBone.new()
    bone.name = "PB_" + bone_name
    bone.bone_name = bone_name
    if parent_idx >= 0:
        skel.set_bone_parent(skel.find_bone(bone_name), parent_idx)

    print("bone count = ", skel.get_bone_count())

func _run():
    var cube = MeshInstance.new()
    cube.name = "Cubi"
    cube.mesh = CapsuleMesh.new()

    var skel = Skeleton.new()
    add_bone(skel, "bone_1")
    add_bone(skel, "bone_2", 0) 


bone count = 1
bone count = 2
- ERROR: get_physical_bone: Index p_bone = -1 is out of bounds (bones.size() = 2).
-   At: scene/3d/skeleton.cpp:652.
- ERROR: get_physical_bone: Index p_bone = -1 is out of bounds (bones.size() = 2).
-   At: scene/3d/skeleton.cpp:652.

error line: https://github.com/godotengine/godot/blob/a51e78528f20c410880b71c978f4038532d99659/scene/3d/skeleton.cpp#L652

I just started with Godot and I can't figure out how to debug this. IE, is it possible to enable stack trace for these errors?
Any suggestion is appreciated!

Godot version 3.2.3
in Engine by (15 points)

2 Answers

+1 vote
Best answer

Stacktraces should be enabled.
The fact that your prints appear before your errors indicates that your code likely does not produce them directly, but by leaving your Skeleton in a corrupt state.

Have you tried your code outside of a tool script? The Editor is a bit different than a regular running environment, maybe it is unsuited for Skeletons?
It would allow to save your creation just as well.

by (2,634 points)
selected by
+1 vote

I ran into the same issue in 3.2.3.
To fix this issue I just kept shuffling the functions around until the errors were gone.

physical_bone.set("bone_name", bone_name)
physical_bone.owner = self
by (16 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.