Search Issue Tracker

Active

Under Consideration for 2022.2.X, 2022.3.X

Votes

15

Found in

2022.2.0b1

Issue ID

UUM-9856

Regression

No

Terrain Toolbox window causes an exception after entering and leaving play mode

--

-

Steps to reproduce:
# Load the attached project
# Ensure that the Terrain Tools window (Window/Terrain/Terrain Toolbox) is open and docked somewhere
# Open Scene Assets/Scenes/SampleScene.unity
# Enter & exit Play Mode

Expected result: nothing happens

Actual result:

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 /Users/ascentress/Desktop/lotad2/Library/PackageCache/com.unity.terrain-tools@5.0.0-pre.3/Editor/TerrainToolbox/TerrainToolboxUtilities.cs:2061)
UnityEditor.TerrainTools.TerrainToolboxUtilities.OnPlayModeChanged (UnityEditor.PlayModeStateChange state) (at /Users/ascentress/Desktop/lotad2/Library/PackageCache/com.unity.terrain-tools@5.0.0-pre.3/Editor/TerrainToolbox/TerrainToolboxUtilities.cs:2290)
UnityEditor.EditorApplication.Internal_PlayModeStateChanged (UnityEditor.PlayModeStateChange state) (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorApplication.cs:441)

 

Reproducible with any version that supports the Terrain Tools package versions 4.0.3 and above.

Package version: 4.0.3, 5.0.0-pre.3 

Tested Editor versions: 2021.3.1f1, 2022.2.0b1

Comments (5)

  1. Freshione

    Jul 07, 2024 13:11

    Tried FLAMINGJEZ solution but now my project has got bricked for modifying the script.

    ScriptableSingleton already exists. Did you query the singleton in a constructor?
    UnityEditor.PackageManager.UI.Internal.PackageManagerProjectSettings:.ctor ()

    Restarting fixes the error message, but now some parts of my game wont work.

  2. rayanivanove

    Jan 11, 2024 16:24

    MELZERIA: You need to clear the error from the console before making the changes in visual studio, for some reason, and then it should work.

  3. Melzeria

    Jul 16, 2023 11:25

    I tried your solution to fix this but everything I add the else and click on save, the script just automatically reverts back to what it had before and I keep getting the error message.

  4. Om1010

    Apr 02, 2023 15:08

    Thanks FLAMINGJEZ, It totally worked and I learned something new that I could've never had!

  5. FlamingJez

    Aug 06, 2022 16:30

    I fixed this myself as it was quite annoying. if you double click the error it should take you into the TerrainToolboxUtilities.cs. The error is that on line 1853 it's trying to call DisabledKeyword when m_PreviewMaterial is null. There's already an if statement checking if it's null, so i just added an else so the line only runs when m_PreviewMaterial has been assigned.

    internal void RevertPreviewMaterial()
    {
    if (m_PreviewMaterial == null)
    {
    GetAndSetActiveRenderPipelineSettings();
    }
    else
    {
    m_PreviewMaterial.DisableKeyword("_SPLATMAP_PREVIEW");
    }
    for (int i = 0; i < m_Terrains.Length; i++)

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.