2
\$\begingroup\$

In Unity, we can use the Apply() function of Texture2D to apply any changes that we've made with SetPixel() or SetPixels().

Is there a way to check whether the texture currently has any unapplied changes? I don't see any relevant properties like IsDirty or HasUnappliedChanges, but perhaps there's a less obvious way to check.

My particular use case is that I have a texture which is normally only used for calculations and does not need to be displayed on the screen, so it's normally not necessary to call Apply() after changing the texture. However, I'd like to be able to preview the texture in the Inspector when a particular component is selected, which does require that the texture is Applied. I'm wondering if Texture2D has a built-in way to check for unapplied changes; if not, it won't be difficult to write custom code for tracking this.

\$\endgroup\$
2
  • \$\begingroup\$ For this use case, since this is only for use in the Editor, why not just write some editor-only code that applies the texture whenever its gameobject is selected? \$\endgroup\$ Sep 13, 2022 at 0:00
  • \$\begingroup\$ @AcmeNerdGames This question is from 21 months ago; I don't even remember what project this was related to, much less the specific reason I needed to check for unapplied changes. I would guess that I was concerned about the performance cost of calling Apply(), though I don't usually concern myself over the performance of Editor code... \$\endgroup\$
    – Kevin
    Sep 13, 2022 at 0:13

1 Answer 1

2
\$\begingroup\$

I've tried Texture2D.updateCount but this apparently does not record the count of unapplied changes. So I just use a separate bool[] to record which textures I've made changes to. Not as efficient as dealing with all the data directly in Texture2D I guess, but it works.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .