Rendering Bones?

Im trying to debug some rotations applied to an animated skeleton, and I would like to see its bones rendered as debuglines.

Is there functionality somewhere to do this?

E.G: a component that would recursively render debuglines.

???

Kind regards

tax

you could use Debug.DrawLine and traverse through the bone hierarchy

Would you happen to know a snippet showing how to traverse children? Preferably in C#?

you can just iterate through the transform of a gameobject to get all children, so something like

foreach( Transform child in transform ) {
 ...
}

the field childCount of a Transform tells you how many childs it has should you require the number for something

I ended up with this

using UnityEngine;
using System.Collections;

public class BoneDebug : MonoBehaviour
{
	void drawbone(Transform t)
	{
		foreach ( Transform child in t)
		{
			float len = 0.05f;
			Vector3 loxalX = new Vector3(len,0,0);
			Vector3 loxalY = new Vector3(0,len,0);
			Vector3 loxalZ = new Vector3(0,0,len);
			loxalX = child.rotation * loxalX;
			loxalY = child.rotation * loxalY;
			loxalZ = child.rotation * loxalZ;
			
			Debug.DrawLine(t.position * 0.1f + child.position * 0.9f,  t.position * 0.9f + child.position * 0.1f, Color.white);
			
			Debug.DrawLine(child.position,  child.position+loxalX, Color.red); 
			Debug.DrawLine(child.position,  child.position+loxalY, Color.green); 
			Debug.DrawLine(child.position,  child.position+loxalZ, Color.blue); 
			drawbone(child);
		}
	}
	void Update ()
	{
		drawbone(transform);
	}
}
1 Like

Thanks for the script. :slight_smile: It works but only in play mode :? It would be more usefull to have something showing Bones in the editor so you know what you are actually working with.

If you replace the Debug.DrawLine calls with Gizmos.DrawLine and call the function from the OnDrawGizmos function, you will be able to see the lines in the scene view while editing.

Now IT WORKS. Thanks for the hints. Someone else helped me because i am not int C sharp

Now You cas see the bones Conection IN Editor Mode You can’t select em directly, have to go throght the Hirarchy Manager but it’s alot better

using UnityEngine;
using System.Collections;

public class BoneDebug : MonoBehaviour
{
   void drawbone(Transform t)
   {
		//renderer.SetWidth(5.0, 2.0);
      foreach ( Transform child in t)
      {
         float len = 0.05f;
         Vector3 loxalX = new Vector3(len,0,0);
         Vector3 loxalY = new Vector3(0,len,0);
         Vector3 loxalZ = new Vector3(0,0,len);
         loxalX = child.rotation * loxalX;
         loxalY = child.rotation * loxalY;
         loxalZ = child.rotation * loxalZ;
         
         Gizmos.DrawLine(t.position * 0.1f + child.position * 0.9f,  t.position * 0.9f + child.position * 0.1f);
         
         Gizmos.DrawLine(child.position,  child.position+loxalX);
         Gizmos.DrawLine(child.position,  child.position+loxalY);
         Gizmos.DrawLine(child.position,  child.position+loxalZ);
         drawbone(child);
      }
	  //LineRenderer.SetWidth(1.0, 1.0);
   }
   void Update ()
   {
   }
   void OnDrawGizmos()
   {
      drawbone(transform);
   }
}

name the script BoneDebug :smile: attach to main Object of the Character

2 Likes

This code snippet was EXACTLY what I was looking for and very helpful. It will help me debug my workflow of my characters from Lightwave to FBX through to Unity.

Thanks for sharing! :slight_smile: