Skip to content

Instantly share code, notes, and snippets.

Created October 11, 2015 04:51
Show Gist options
  • Save tsubaki/ea6ece1cd9a851ff977e to your computer and use it in GitHub Desktop.
Save tsubaki/ea6ece1cd9a851ff977e to your computer and use it in GitHub Desktop.
update SkinnedMesh
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Assertions;
using System;
public class SkinnedMeshUpdater : MonoBehaviour
SkinnedMeshRenderer original;
void Update ()
if (Input.GetKeyDown (KeyCode.Space)) {
UpdateMeshRenderer (original);
void OnDrawGizmosSelected ()
var meshrenderer = GetComponentInChildren<SkinnedMeshRenderer> ();
Vector3 before = meshrenderer.bones [0].position;
for (int i = 0; i < meshrenderer.bones.Length; i++) {
Gizmos.DrawLine (meshrenderer.bones [i].position, before);
UnityEditor.Handles.Label (meshrenderer.bones [i].transform.position, i.ToString ());
before = meshrenderer.bones [i].position;
public void UpdateMeshRenderer (SkinnedMeshRenderer newMeshRenderer)
// update mesh
var meshrenderer = GetComponentInChildren<SkinnedMeshRenderer> ();
meshrenderer.sharedMesh = newMeshRenderer.sharedMesh;
Transform[] childrens = transform.GetComponentsInChildren<Transform> (true);
// sort bones.
Transform[] bones = new Transform[newMeshRenderer.bones.Length];
for (int boneOrder = 0; boneOrder < newMeshRenderer.bones.Length; boneOrder++) {
bones [boneOrder] = Array.Find<Transform> (childrens, c => == newMeshRenderer.bones [boneOrder].name);
meshrenderer.bones = bones;
Copy link

tsubaki commented Oct 11, 2015

screen shot 2015-10-08 at 18 35 09

Copy link

Nice solution! It works.

Copy link

same for me, thanks for this code snippet!

Copy link

Karam000 commented Apr 4, 2021

works fine thanks a lot

Copy link

Working great, thanks!

Copy link

WILEz75 commented Sep 8, 2021

Excellent solution, I had this problem for years.
But you should create a editor script that makes the changes permanent. (Input space not work in editor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment