Author Topic: Editor Script Updates Sprite Parent Position, Sprite Stays Put  (Read 3931 times)

David Foster

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Editor Script Updates Sprite Parent Position, Sprite Stays Put
« on: February 11, 2014, 07:50:44 AM »
I have a simple editor script that sets a game object's local position x and y based on an enumeration value set in the inspector. It is happening OnSceneGUI when the value changes. The issue is, if there's a sprite parented to the game object, it doesn't redraw the sprite at its new location. The only way I have found to do that is to click out of Unity and back in, or save the scene.

I have tried SceneView.RepaintAll() and NGUIEditorTools.RepaintSprites() to no avail. This doesn't appear to be a Unity issue either, as primitives (e.g., quads) are redrawn, it's just sprites that are not. Any ideas? Cheers.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Editor Script Updates Sprite Parent Position, Sprite Stays Put
« Reply #1 on: February 11, 2014, 08:01:48 PM »
UnityEditor.EditorUtility.SetDirty on the sprite. Whenever you modify something in the editor, you must mark the modified script as dirty.

David Foster

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Editor Script Updates Sprite Parent Position, Sprite Stays Put
« Reply #2 on: February 12, 2014, 07:13:11 AM »
Cheers Michael, but that isn't solving the problem. Here is a quick breakdown of the issue in case I've been unclear:

  • Editor script edits a transform's position x and y.
  • A sprite parented to said transform moves with it, but is not drawn in the new location in the editor scene view.
  • So, after editing transform, I call EditorUtility.SetDirty(sprite), SceneView.RepaintAll() and NGUIEditorTools.RepaintSprites()
  • Sprite is still not drawn in the new location until I click out of Unity and back in, or if I save the scene.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Editor Script Updates Sprite Parent Position, Sprite Stays Put
« Reply #3 on: February 13, 2014, 02:59:33 AM »
Hmm, well the only reason I can think of why this would happen is if the panel has the static flag turned on... but that one is for run time, not edit time. It should work just fine at edit time regardless. Are you on Unity 4 or 3?

RepaintSprites() is actually a function that repaints editor and inspector windows, so isn't relevant in your case.