Skip to content

Instantly share code, notes, and snippets.

@pinheadtf2
Created July 30, 2022 18:58
Show Gist options
  • Save pinheadtf2/7804828d695b7e60157a6d70cccf3e32 to your computer and use it in GitHub Desktop.
Save pinheadtf2/7804828d695b7e60157a6d70cccf3e32 to your computer and use it in GitHub Desktop.
Unity Editor Mesh Saver
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.Collections;
// Usage: Attach to an object, assign target gameobject (from where the mesh is taken), Run, Press savekey
public class SaveMeshInEditor : MonoBehaviour
{
public string saveName = "SavedMesh";
public Transform selectedGameObject;
void Start()
{
StartCoroutine(WaitFunc());
}
IEnumerator WaitFunc() {
yield return new WaitForSeconds(5);
SaveAsset();
}
void SaveAsset()
{
var mf = selectedGameObject.GetComponent<MeshFilter>();
if (mf)
{
var savePath = "Assets/" + saveName + ".asset";
Debug.Log("Saved Mesh to:" + savePath);
AssetDatabase.CreateAsset(mf.mesh, savePath);
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment