Procedural-Landmass-Generation icon indicating copy to clipboard operation
Procedural-Landmass-Generation copied to clipboard

Shader[Custom/Terrain]: Incompatible texture type

Open Sparksx opened this issue 6 years ago • 4 comments

Hi,

I'm currently at ep18 and i got this strange warning thousands times in my console: Metal: Shader[Custom/Terrain]: Incompatible texture type [MTLTextureType2D] of texture bound at index 1, expected [MTLTextureType2DArray]

After some researches, I got this warning until I clic on update button in my default texture (Terrain Assets/Default Texture) The only thing we can found online is this stackoverflow question

Did you have any idea for a fix about that? I'm on unity 2019.3.3f1

Thanks

Sparksx avatar Apr 08 '20 15:04 Sparksx

There is a race condition here. To solve it I simply used Invoke and created the terrain 0.1 seconds later:

TerrainGenerator.cs

	void Start()
	{
		Invoke("CreateTerrain", 0.1f);
	}

	public void CreateTerrain()
	{
		textureSettings.ApplyToMaterial(mapMaterial);
		textureSettings.UpdateMeshHeights(mapMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);

		float maxViewDst = detailLevels[detailLevels.Length - 1].visibleDstThreshold;
		meshWorldSize = meshSettings.meshWorldSize;
		chunksVisibleInViewDst = Mathf.RoundToInt(maxViewDst / meshWorldSize);

		UpdateVisibleChunks();
	}

erikbethke avatar Jun 24 '20 01:06 erikbethke

Crap. I tried your fix but still see the Metal errors. It does feel like a race condition... Code seems to be sending a single texture rather than an array (i.e. splat map)...

rikkcarey avatar Jun 24 '20 01:06 rikkcarey

So it is an ugly race condition, as my startup code has become more heavy, I have had to increase from 0.1 seconds to now 0.3 seconds. I am sure there is a stronger callback we should be using when all of the shaders have been created... but try a longer invoke...

erikbethke avatar Jun 28 '20 04:06 erikbethke

I finally solved this for me game for good by creating the terrain mesh behind the view of a full screen view that is modal waiting for the player's action.

erikbethke avatar Sep 10 '20 02:09 erikbethke