Hi,
I’ve created a script to replace (in Editor) all the MeshFilter’s mesh in my scene by the mesh “meshToAssign” but i’m having trouble to get my mesh list.
Here is my code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ReplaceMesh : MonoBehaviour
{
public Mesh meshToReplace;
public Mesh meshToAssign;
public List<MeshFilter> meshFilterToWorkOn;
[ContextMenu("FindMeshRendererToWorkOn")]
public void FindMeshRendererToWorkOn()
{
meshFilterToWorkOn.Clear();
MeshFilter[] meshFilterAll = FindObjectsOfType<MeshFilter>();
int meshFilterAllLength = meshFilterAll.Length;
for (int i = 0; i < meshFilterAllLength; i++)
{
if (meshFilterAll*.sharedMesh == meshToReplace)*
meshFilterToWorkOn.Add(meshFilterAll*);*
}
}
[ContextMenu(“ReplaceAllMeshInList”)]
public void ReplaceAllMeshInList()
{
int meshFilterToWorkOnCount = meshFilterToWorkOn.Count;
for (int i = 0; i < meshFilterToWorkOnCount; i++)
meshFilterToWorkOn*.mesh = meshToAssign;*
}
}
It seems like the variable “meshToReplace” isn’t equal to “meshFilterAll.sharedMesh” but when i tryed with “meshFilterAll_.mesh” a error has appear in the console when i execute the command.
Can you guys help me ?_