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

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 :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.

1 Like

I’m having this exact same problem, and haven’t found any solutions yet myself. Anyone else have insight into this?

2 Likes

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.

Hello,
did not notice errors at creation time but those when going to the paint terrain tab right after creating it

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.

1 Like

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 !!!

3 Likes

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.

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.

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 :smile:

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.

1 Like

THANK YOU!, This worked for me, finallyyy

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.

3 Likes

this worked for me, i have been trying for weeks thank you thank you thank you thank you

1 Like

I had this problem and I think it is because I had the Terrain Toolbox window open (or attached to somewhere in the unity window). Just close the Terrain Toolbox window and the error should dissapear.

20 Likes

How did you manage to change? If the script itself is in the cache? And every 10 seconds the code is overwritten?

This worked for me. No need to edit any script!.

3 Likes

I changed the line and it worked but now it says Incompatible keyword states

please file a bug report for this issue, looks like something we should address.

1 Like

Restarting the project did it for me

This worked for me, thank you