Search code examples
c#androidunity-game-enginetexture2dorthographic

How can I show my SetPixels() texture changes without having to zoom my orthographic camera?


This is my first question here! I hope you'll bear with me. :)

I'm working on flood fills on Unity, and while I'm already able to fill shapes on my Texture2D, I can only see the changes when I zoom in with my orthographic camera. When I zoom out, it goes back to looking like the original image. What is also weird is that this happens in both my editor and my game scene, as well as when I build it on Android.

What could possibly be causing this? What can I do to prevent this? Am I missing something?

I've tried using images of different sizes, but it still behaves the same way.

This is what it looks like after filling a shape using SetPixels() when zoomed in. The red circle is originally white. Notice that the editor is not showing the change. The image's size is 1920x1080:

This is how it then looks like when you zoom out a bit. The game scene now doesn't show the change as well. I've also included the properties of the texture in the screenshot:

I also observed that it might not even be about the camera zoom, as the changed pixels also appear if I scale up the image in the inspector even if I don't zoom in as much:


Solution

  • You are only setting the pixels for a specific mipmap value (level 0 by default), but you need to extend the changes to the mipmap level that the camera is currently viewing.

    You can do this by calling Texture2D.Apply() with updateMipMaps set to true (which is the default) after you set the pixels for the mipmap level 0 (which is probably what you are already doing).