Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Terrain Toolbox (Unity 2021.2.10f1 and Toolbox 4.0.3) MissingReferenceException after Terrain Create

Discussion in 'World Building' started by Auticus, Feb 16, 2022.

  1. Auticus

    Auticus

    Joined:
    Jul 18, 2013
    Posts:
    99
    After creating a brand new terrain using the Unity Terrain Toolbox (version 4.0.3) my project now constantly has the exception:


    MissingReferenceException: The object of type 'Material' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    UnityEditor.TerrainTools.TerrainToolboxUtilities.RevertPreviewMaterial () (at Library/PackageCache/com.unity.terrain-tools@4.0.3/Editor/TerrainToolbox/TerrainToolboxUtilities.cs:1853)
    UnityEditor.TerrainTools.TerrainToolboxUtilities.OnPlayModeChanged (UnityEditor.PlayModeStateChange state) (at Library/PackageCache/com.unity.terrain-tools@4.0.3/Editor/TerrainToolbox/TerrainToolboxUtilities.cs:2082)
    UnityEditor.EditorApplication.Internal_PlayModeStateChanged (UnityEditor.PlayModeStateChange state) (at <ac4382394009481fa61779d0ab47a96f>:0)

    Does anyone know a workaround to resolve this? Or should I scrap the toolbox and try to create terrains the normal way?

    My project is using URP if that matters.
     
    inkopp36 likes this.
  2. mezzanine510

    mezzanine510

    Joined:
    Mar 7, 2018
    Posts:
    2
    I'm having this exact same problem, and haven't found any solutions yet myself. Anyone else have insight into this?
     
    inkopp36 likes this.
  3. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    8,745
    Right now the Toolbox is so full of issues like this that I can't recommend even using it for testing purposes. It is just constantly throwing up errors when doing even basic tasks.
     
  4. Erenquin

    Erenquin

    Joined:
    Apr 9, 2018
    Posts:
    138
    Hello,
    did not notice errors at creation time but those when going to the paint terrain tab right after creating it
    upload_2022-4-18_17-7-30.png
     
  5. evanvlane

    evanvlane

    Joined:
    Feb 18, 2019
    Posts:
    4
    Is there any Unity dev support looking at this?
    It's a released Unity official package and it's been out of preview since September of 2021.
    It looks like there were several updates right after 4.0.0, and then nothing.

    I've submitted a bug report on this. It's really annoying and surprising to see in a released Unity official package.
     
    Erenquin likes this.
  6. husseinhiua

    husseinhiua

    Joined:
    Dec 4, 2021
    Posts:
    1
    hi
    I have soluiton which work fine for me
    go to :
    Packages /Terrain Tools /Editor / Terrain ToolBox / Terrain ToolBox Utilities.cs

    and go to method ( RevertPreviewMaterial() ) (line 1847 ) and write (return) ,then save the script

    by this way i disable this method, which work fine form me ( No MissingReferenceException or other Exception)

    However I know this isn't ideal solution (you may face some error when use paintTree )
    but I can't find other solution until now !

    see this image !!!
     

    Attached Files:

    • sda.png
      sda.png
      File size:
      232 KB
      Views:
      55
    Last edited: Aug 15, 2022
  7. OwenDuffyColum

    OwenDuffyColum

    Joined:
    Feb 6, 2021
    Posts:
    1
    I tried this, but every time I added the return; line where you have it, when I save the script, my change automatically gets deleted for some reason.
     
  8. aktopshelf

    aktopshelf

    Joined:
    Jun 26, 2022
    Posts:
    1
    Close Unity Editor, but leave Visual Studio open with the code then add the "return;" line. I can't confirm it will work, but judging by the warning my Visual Studio gave me Unity Editor was a little mad at me for trying to change it while it was using that script at the time. I accepted the revert Visual Studio was offering when it asked, but quickly added the line back in and hit save before it was looking and that worked for me.
     
  9. moog2001

    moog2001

    Joined:
    Jun 23, 2021
    Posts:
    2
    I have this problem too, It was working for me on a project I had created earlier that I updated the version of the editor maybe twice or three times.
    But I reset my packages to default and this error is keep appearing, really bugging me out :D
     
  10. moog2001

    moog2001

    Joined:
    Jun 23, 2021
    Posts:
    2
    I GOT IT!
    So what you gotta do is download one of the previous of LTS 2021 and start a project. Maybe add a cube or something save and close the project. After that update the project editor version to latest version and there won't be this error.
     
    Erenquin likes this.
  11. Bloodshot1337

    Bloodshot1337

    Joined:
    Sep 19, 2022
    Posts:
    1
    THANK YOU!, This worked for me, finallyyy
     
  12. DavidQi1970

    DavidQi1970

    Joined:
    Apr 16, 2020
    Posts:
    1
    Change the line to this:
    if (m_PreviewMaterial != null) m_PreviewMaterial.DisableKeyword("_SPLATMAP_PREVIEW");

    Be noticed that you may do it twice, I do not know why but finally things settled.
     
    OnniOnniOnni likes this.
unityunity