• Unity
  • [Unity] Skeleton.FindBone finds all instances of a bone

  • Изменено
Related Discussions
...

Hi, just wondering what your recommended method (in case I've missed it) would be in this situation.

I have 2 separate game objects that both use use the same skeleton animation, they use different skins however (a player skin and an enemy skin.)

I added code to the player object to manipulate the bones to look towards the mouse, this is what I use to find the bones:

animation = GetComponent<SkeletonAnimation>();
neck = animation.skeleton.FindBone  ("neck");
leftShoulder = animation.skeleton.FindBone ("arm_upper_far");
rightShoulder = animation.skeleton.FindBone  ("arm_upper_near");

The problem I have is that this will also find the "enemy" bones and so it will apply any changes I make to the bones on both of them.

Looking at the code for FindBone this does look intended, so I'm assuming that I should be using something else so that I only select the players bones. What should I do instead?

Thanks.

Bone and BoneData are 2 different things. If you alter BoneData it will effect anything that references that BoneData.

Bone itself doesn't exist until a Skeleton is created.

That explains why the problem occurs Mitch, thank you! I did not realise BoneData + Bone were two very different things.

Found my solution, I had not looked at the latest goblins.cs example found here:
https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-unity/Assets/Examples/Scripts/Goblins.cs

Confusion occurred because I was looking at out of date examples and saw people rotating the BoneData instead of the Bone. Since I was not calling rotations inside of UpdateLocal I was obviously not seeing any changes to the bones when locally rotating them.

Cool - glad you're all sorted 🙂

You can take a look at the Gauge example for an extremely straight forward method to modifying bones during runtime.

Just wanted to say this reminded me to finally fix my stupid, stupid modification of BoneData. Because I have multiple copies of the same skeleton, I ended up having it just create duplicate copies in memory so that I could modify the initial position of some bones on a per character basis. The Goblins example (using UpdateLocal) is obviously the correct way to do it, and now I'm not allocating 30mb for every additional character.