That’s quite rude of you to assume that I’m attempting to cheat him. He gave up, I made him aware of the glitch and he told me to just take the script for free because he doesn’t want to fix it.
Whew, well that’s good to know, and I’m sorry for the assumption. I’ve edited my reply, as I’m not sure where you’re getting the error. Also, there’s a Biome class being referenced, so the issue could be from there as well.
I seem to be missing something as I can’t make the script work in a new scene, but I think I know the problem. In the Initialize() function, it sets the splatMapData (line 57). However, when you resize the terrain, you aren’t updating the splatMapData size. So you could put that line in a Update function for a sloppy fix, or call it every time you change the size of the terrain.
I’m not changing the size of the terrain mid-game though.
And to make the script work you place it on the terrain, you don’t need to place down Biome.cs, then you assign the terrain variable to the terrain you have the script placed on.
I just tested it, spawning in default terrain - adding a texture and changing the width/length. It then throws me an error so it definitely is a size problem
BIG EDIT:
I just tested it out, re-sized terrain that DOESNT have a texture it works on! So somehow adding a texture is causing the problem
Originally I was testing a terrain without textures as well, but I’ve added 3 textures, drawn a bit on the terrain, then resized it in the Terrain Settings, both out of and in-game, with no errors. No wonder the original programmer gave up, I can’t even reproduce the error lol
I finally got the error when I made the terrain 800 X 600.
IndexOutOfRangeException: Array index is out of range.
(wrapper managed-to-managed) object:ElementAddr_3_4 (object,int,int,int)
TESTPlacerScript.Spawn () (at Assets/@MYSTUFF/Scripts/TESTPlacerScript.cs:79)
TESTPlacerScript.Start () (at Assets/@MYSTUFF/Scripts/TESTPlacerScript.cs:34)
So we can confirm then that the problem occurs when both of these conditions are met:
A) The terrain has textures
B) The terrain size is larger than default
I slightly contest that, it works for sizes a bit larger than 500X500, I’ve had success with 530X530. But 550X550 is enough to trip the error. I’m currently thinking the array is getting too big.
Most people would give up by now, but I’ll chalk this up as C# practice.
Thanks, it would mean the world if I could get this running because it is quite literally one of the biggest gameplay-required mechanics I need to get my game going
I’m not sure if this will work for you, and I’m pretty sure this isn’t good programming practice, but this just catches the error so it doesn’t show and/or crash and from my experience, it seems to work OK:
for (int i = 0; i < mTextures; i++)
{
try
{
if (comp < splatMapData[(int)TerrainCord.z, (int)TerrainCord.x, i])
ret = i;
}
catch {}
}
Give that a try and see if it works OK (replace the lines between about 77-81 with that). It works with even 5000X5000 terrains and spawns objects like it does at 300X300.