Search Unity

Sprite Animation Sheet and ExecuteInEditMode

Discussion in 'Scripting' started by Marc, Nov 6, 2008.

  1. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    Im doing a sprite animation sheet, which is basically what is found on the wiki with some modifications.

    Now the scripts works fine when i press run in the editor and it works fine in builds aswell.

    What i would like to do is make the script reflect the first frame of the animation in the editor, so that level designers can place the objects using sprites more acurately with out seeing the entire sheet, so i figured ExecuteInEditMode is what i want, and it is!

    It works but now the editor complains that Materials are beeing leaked into the scene, which ofc is true as i was usin

    Code (csharp):
    1.  
    2. renderer.material
    3.  
    I changed all placed in the code of the script using renderer.material to

    Code (csharp):
    1.  
    2. If(Application.IsEditor  !Application.IsPlaying)
    3. {
    4.      renderer.sharedMaterial.SetTextureOffset();
    5. }
    6. else
    7. {
    8.      renderer.material.SetTextureOffset();
    9. }
    10.  
    Now this works and the editor don't complain about leaks no more, but now the Asset server flags the materials touched by the scripts as changed!

    How can i prevent this from happening?

    Regards,
    Marc