[SOLVED] Why does this happen? Do I misunderstand how Texture2D works?

Hello all. Before I start talking more in depth, thank you for reading this.
Ok so, basically im having troubles with Unity when doing my project. Im making my own editor, and im doing a system to merge all the tiles, to reduce the number of GameObjects on screen so the performance will be better. The thing is, when merging all the tiles depending of the GameObject’s (which contains the tiles) position the texture does strange things. Here you have some gifs that show what im saying perfectly:
[Good One]: https://media.giphy.com/media/3o7OsSeNmouUdAyssU/giphy.gif
[Bad One]: https://media.giphy.com/media/xTg8B3BgUpfri9UDDy/giphy.gif

By using “bad or good” I’m trying to specify which should be the desired result (but that’s evident I guess).
As you can see it puts two shtty bars of 1px each there.
Now, what happens if I put more structures there:
[With more structures]: https://media.giphy.com/media/xTg8B2Tr3BeyRqIryU/giphy.gif

I guess this has to do with alpha, but I don’t know exactly. By the way, I’m using TextureFormat.RGBAFloat for the texture format.

As I said, thank you so much. If its needed to show some code, I will.

You’re going to have to be far more specific on what you’re doing to merge the tiles.

Well, I’ll try to explain it the best I can.

First, the tiles are individual gameobjects, so I just collect them in an array.
Then I calculate the maximum x,y position, so it helps me to know the width and height of the texture.
(loop)
Once I create the texture I just pick the gameobjects one by one and start taking their sprite.
I get all the pixels with GetPixels, then I set the pixels in the texture with SetPixels.
(end of the loop)
Apply.

Notice I have the apply outside the loop. I don’t know if that’s a problem.
That’s all what I do. Thank you for the reply.

I couldn’t say exactly where you’re going wrong just from that description, but I’m guessing it could be worked around by making sure your initial texture is clear (color 0,0,0,0) before you start doing any of your get / set pixels.

However I kind of wonder why you’re doing it this way at all. You presumably already have sprites, and those sprites are (presumably) in a sprite atlas. Why not just merge the sprite meshes together and keep the original sprite atlas and UVs? Should be far more efficient than what you’re doing unless you’ve got hundreds of thousands of sprites.

1 Like

Ok, I just filled the texture with Color.Clear and now works perfectly!! Thank you so much. It was simple, but I didn’t know the texture’s pixels color were null.