Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

ProBuilder [BUG] Mesh Collider keep getting lost whenever i disable the gameobject for a while

Discussion in 'World Building' started by St4va, Jun 28, 2019.

  1. St4va

    St4va

    Joined:
    Jun 19, 2014
    Posts:
    5
    So yeah, whenever I disable a probuilder mesh for a while (in editor), and turn it on again after a while, it missing it's a mesh in the mesh collider component. Please fix it
     
    drewvancamp likes this.
  2. St4va

    St4va

    Joined:
    Jun 19, 2014
    Posts:
    5
    Anyway, for anyone that looking for a solution, this is mine.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public class MeshRest : EditorWindow
    5. {
    6.     readonly string recordButton = "Rest Meshs";
    7.  
    8.     [MenuItem("StaviTools/MeshRest")]
    9.     static void Init()
    10.     {
    11.         MeshRest window =
    12.             (MeshRest)EditorWindow.GetWindow(typeof(MeshRest));
    13.     }
    14.  
    15.     void OnGUI()
    16.     {
    17.         if (GUILayout.Button(recordButton))
    18.         {
    19.             object[] obj = Resources.FindObjectsOfTypeAll(typeof(MeshCollider));
    20.             foreach (object o in obj)
    21.             {
    22.                 MeshCollider g = (MeshCollider)o;
    23.  
    24.                 //if there is no mesh in the meshCollider:
    25.                 if(g.sharedMesh == null)
    26.                 {
    27.                     Mesh test = g.transform.GetComponent<MeshFilter>().mesh;
    28.                     g.sharedMesh = test;
    29.                 }
    30.             }
    31.         }
    32.     }
    33. }
     
    drewvancamp likes this.
  3. drewvancamp

    drewvancamp

    Joined:
    Oct 9, 2015
    Posts:
    1
    thank you so much! this happened to me, i guess because i had disabled a large number of probuilder objects while working on a different section of the game world and then suddenly my game was very broken and i had no idea why

    then i wasn't sure how to assign the mesh after trying several things, so this script worked great for me

    thanks for helping me fix my game!
     
  4. St4va

    St4va

    Joined:
    Jun 19, 2014
    Posts:
    5
    Hey, I soon discovered that MeshFilter also loses it's mesh, that's more problematic. I did found a simple solution.
    Ctrl + D (copy and paste you world gameObject, and delete the previous one)

    Good luck with your game