I was going to show you gents my code, but then I thought (a) they really don’t deserve that (it’s so bad, not going to inflict it upon you), and (b) … I’m not sure what part is the issue … so let’s get this narrowed down.
I have noise generation code that works. I can display it in the editor as a single tile, manipulate the value, see change, save and PNGs and they all do what I would expect.
I have code that takes these textures and applies them to in editor Planes so I can see them.
they all use the same - and LAST texture generated.
In the picture you can see the testing (output to pngs and assets) showing 6 distinct patterns.
I loop thru these, assign to planes … and get the same [last] texture.
I’ve been going thru my code and adding new() this and new() that, and nothing is working.
the textures sent into this method are, for sure, distinct (I tested it), but is there something in here that would cause all of my object to use the same texture???
The added arrays were simply an attempt to break the texture re-use. they can be removed. they didn’t work.
you can see the liberal use of new()
public GameObject NewPlane(int x, int y, Vector3 pos, Vector3 size, Texture2D texture, string name)
{
MapGenerator mapGenerator = UnityEngine.Object.FindObjectOfType<MapGenerator>();
planes = new GameObject[(int)mapGenerator.WorldTileDimensions.x, (int)mapGenerator.WorldTileDimensions.y];
planes[x, y] = GameObject.CreatePrimitive(PrimitiveType.Plane);
planes[x, y].name = name;
planes[x, y].transform.position = pos;
planes[x, y].transform.localScale = size;
//plane.transform.localScale = scale;
Material material = new Material(Shader.Find("Unlit/Color"));
material.color = Color.white;
Renderer planeRenderer = planes[x, y].GetComponent<Renderer>();
planeRenderer.sharedMaterial.mainTexture = texture;
planeRenderer.sharedMaterial.color = Color.white;
return planes[x, y];
}
would something
for (int x = 0; x < WorldTileDimensions.x; x++)
{
for (int y = 0; y < WorldTileDimensions.y; y++)
{
worldTilesTextureMaps[x,y] = textureGenerator.TextureFromHeightMap(worldTilesNoiseMaps[x, y]);
tilePosX = (x * TileSize) * 10;
tilePosY = (y * TileSize) * 10;
worldTiles[x, y] = mapDisplay.NewPlane(
x,
y,
new Vector3(tilePosX, 0, tilePosY),
new Vector3(TileSize - 1, 1, TileSize - 1),
worldTilesTextureMaps[x, y],
$"NoiseTile[{x}][{y}]");
worldTiles[x, y].SetParent(noiseTileContainer,true);
}
}
in this cause the texture re-use?
I’ve already shared more code than I intended, as I am currently reverting this to an earlier version without the mass of “NEW!” and “ARRAYS!” …
I intended to just ask: Guys … what causes multiple objects to use the same texture, despite being given different ones?