Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

CheckConsistency: Transform child cant be loaded

Discussion in 'Scripting' started by andsee, Jul 3, 2012.

  1. andsee

    andsee

    Joined:
    Mar 20, 2012
    Posts:
    88
    In trying to track down a unity crash i have created a simple script which is resulting in the following error 'CheckConsistency: Transform child can't be loaded' whenever you switch to play mode and back from the editor.

    The script simply takes a reference to another gameobject which it will clone and put in the same parent as the original. It uses the DontSave flag to avoid this cloned object being saved. Of note the error does not occur if the cloned object is in the root.

    To recreate the problem create a blank scene and add a gameobject 'Duplicator' with the below script. Then create another blank gameobject 'Parent'. Place a cube as a child of this and drag the cube object to the 'Duplicate Me' field of 'Duplicator' the cube should be duplicated. Now hit run and check the console.
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. [ExecuteInEditMode]
    5. public class TestDontSave : MonoBehaviour
    6. {
    7.     public GameObject duplicateMe = null;
    8.     private GameObject duplicated = null;
    9.     private GameObject duplicatedInstance = null;
    10.  
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.         if (duplicateMe != duplicated)
    15.         {
    16.             if (duplicatedInstance != null)
    17.             {
    18.                 DestroyImmediate(duplicatedInstance);
    19.                 duplicatedInstance = null;
    20.             }
    21.             if (duplicateMe  duplicateMe.active)
    22.             {
    23.                 duplicatedInstance = (GameObject)Instantiate(duplicateMe, new Vector3(2.0f, 2.0f, 0.0f), Quaternion.identity);
    24.                 duplicatedInstance.hideFlags = HideFlags.DontSave;
    25.                 duplicatedInstance.transform.parent = duplicateMe.transform.parent;
    26.             }
    27.             duplicated = duplicateMe;
    28.         }
    29.     }
    30.  
    31.     void OnApplicationQuit()
    32.     {
    33.         RemoveDupe();
    34.     }
    35.  
    36.     void OnDisable()
    37.     {
    38.         RemoveDupe();
    39.     }
    40.  
    41.     void RemoveDupe()
    42.     {
    43.  
    44.         if (duplicatedInstance != null)
    45.         {
    46.             duplicatedInstance.transform.parent = null;
    47.             DestroyImmediate(duplicatedInstance);
    48.             duplicatedInstance = null;
    49.             duplicated = null;
    50.         }
    51.     }
    52. }
    53.  
    I've added a bug (case 474916) but if anyone knows what I'm doing wrong I would be grateful if they could let me know. I have a more complex script that does a very similar action to the above and in a more complex scene it causes unity to crash with the following stack trace which is very close to where the above error is printed from:

    Code (csharp):
    1.  
    2. (0x00624DE4) c:\buildagent\work\14194e8ce88cdf47\runtime\graphics\transform.cpp (1507): Transform::SetCacheDirty
    3. (0x007309BC) c:\buildagent\work\14194e8ce88cdf47\runtime\serialize\awakefromloadqueue.cpp (274): AwakeFromLoadQueue::InvokePersistentManagerAwake
    4. (0x00730DA9) c:\buildagent\work\14194e8ce88cdf47\runtime\serialize\awakefromloadqueue.cpp (142): AwakeFromLoadQueue::PersistentManagerAwakeFromLoad
    5. (0x00733826) c:\buildagent\work\14194e8ce88cdf47\runtime\serialize\persistentmanager.cpp (1094): PersistentManager::IntegrateAllThreadedObjectsStep2
    6. (0x006B88BE) c:\buildagent\work\14194e8ce88cdf47\runtime\misc\saveandloadhelper.cpp (914): CompleteAwakeSequence
    7. (0x006BAE2D) c:\buildagent\work\14194e8ce88cdf47\runtime\misc\saveandloadhelper.cpp (938): CompletePreloadManagerLoadLevelEditor
    8. (0x0068486A) c:\buildagent\work\14194e8ce88cdf47\runtime\misc\preloadmanager.cpp (700): PreloadLevelOperation::IntegrateMainThread
    9. (0x0068615B) c:\buildagent\work\14194e8ce88cdf47\runtime\misc\preloadmanager.cpp (424): PreloadManager::UpdatePreloadingSingleStep
    10. (0x00686230) c:\buildagent\work\14194e8ce88cdf47\runtime\misc\preloadmanager.cpp (486): PreloadManager::WaitForAllAsyncOperationsToComplete
    11. (0x006B9C8B) c:\buildagent\work\14194e8ce88cdf47\runtime\misc\saveandloadhelper.cpp (967): LoadSceneEditor
    12. (0x00B9A47D) c:\buildagent\work\14194e8ce88cdf47\editor\src\application.cpp (1372): Application::LoadSceneInternal
    13. (0x00B9A969) c:\buildagent\work\14194e8ce88cdf47\editor\src\application.cpp (2257): Application::SetIsPlaying
    14. (0x00B9BF8C) c:\buildagent\work\14194e8ce88cdf47\editor\src\application.cpp (1181): Application::TickTimer
    15. (0x00C05E1A) c:\buildagent\work\14194e8ce88cdf47\editor\platform\windows\wineditormain.cpp (324): MainMessageLoop
    16. (0x00C06C4D) c:\buildagent\work\14194e8ce88cdf47\editor\platform\windows\wineditormain.cpp (712): WinMain
    17. (0x08DC52FC) ((module-name not available)): (filename not available): (function-name not available)
    18. (0x01B175D2) (Unity): (filename not available): g_auedo
    I'm using Unity 3.5.3f3 on Windows 7 64bit.
     
    Last edited: Jul 3, 2012
  2. DuckMaestro

    DuckMaestro

    Joined:
    Oct 10, 2012
    Posts:
    3