Terrain Splat 0 is null

SplatPrototype[] terrainTexture = new SplatPrototype[1];
        terrainTexture[0] = new SplatPrototype(); 
        terrainTexture[0].texture = (Texture2D)Resources.Load("Assets/Standard Assets/Terrain Assets/Terrain Textures/Grass (Hill)");
        t.terrainData.splatPrototypes = terrainTexture;

The last line produces the error “Terrain Splat 0 is null”

What am I doing wrong?
I have tried different paths for the asset. Can’t figure it out, the path should be right.

Just guessing here, but maybe the spaces in the path could create a problem. Other than that, I know the “Standard Assets” folder is somewhat sealed and hard to reach from other folders and such. You might want to try placing it in another folder.

I got the error when I deleted the splat map from the terrain from the asset folder, not triggered by one of my scripts but by unity itself.

Thanks, I tried it but without luck. Any other ideas?

I found the error.
To load a resource at runtime, it seems it must be placed in a folder(or subfolder to) called “resources”.
I found this, and I now have GoodDirt.

arggggggg how stupid is that. Been trying to apply a texture to a terrain for over a week now.
Thanks for posting your solution.

The errors about terrain splats are because you have a terrain with empty texture references Select your terrain, and make sure all the entries defined in the “Paint” tab are assigned to valid textures.

Holy necro, batman! You answered a 2 year old question that had already been answered. :slight_smile:

1 Like

And with an irrelevant answer too. It’s not quite a record, but it must be close.