- Home /
Make bones visible when playing
I would like to have a way to draw the bones of my Skinned Meshes to the screen. Is there something in the asset store, a tutorial, or a simple way of doing this? I have searched and can't seem to find a solution.
For what purpose do you want to display the bones? Do you want to display them in the editor only or in a build? When you want to display them in the editor for debugging purposes you can use Debug.DrawLine().
If you want to view them in a build it's probably easier to "model" them as mesh. Bones are not like real bones, they are just Transforms in a hierarchically setup.
I can post an example for the first case...
We want to display the bones during runtime. We allow users to manipulate the bones, which is already done. But, I can't figure out how to draw them. The problem with modeling them out is the fact that we are not the ones creating the models, and there will be quite a lot.
Actually, I just came up with an idea. Ins$$anonymous$$d of drawing bones, I guess we could draw a sprite where the joint is. This will actually probably be better for the tech illiterate, which is who we are sort of targeting.
Thanks for the help though, it really got me thinking.
Answer by DoctorWhy · Oct 09, 2012 at 10:28 PM
Actually, I just came up with an idea. Instead of drawing bones, I guess we could draw a sprite where the joint is. This will actually probably be better for the tech illiterate, which is who we are sort of targeting.
Answer by Bunny83 · Oct 09, 2012 at 10:24 PM
Here's a small script that should draw a line between all bones inside the editor. I wrote this from scratch. I haven't tested it but it should work.
// DrawBones.cs
using UnityEngine;
public class DrawBones : MonoBehaviour
{
private SkinnedMeshRenderer m_Renderer;
void Start()
{
m_Renderer = GetComponentInChildren<SkinnedMeshRenderer>();
if (m_Renderer == null)
{
Debug.LogWarning("No SkinnedMeshRenderer found, script removed");
Destroy(this);
}
}
void LateUpdate()
{
var bones = m_Renderer.bones;
foreach(var B in bones)
{
if (B.parent == null)
continue;
Debug.DrawLine(B.position, B.parent.position, Color.red);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613082117im_/https://answers.unity.com/themes/thub/images/avi.jpg)