Arcadia icon indicating copy to clipboard operation
Arcadia copied to clipboard

ArcadiaState not compatible with new Prefab editor

Open nasser opened this issue 7 years ago • 3 comments

Unity has a new prefab editor and ArcadiaState does not seem to work with it. Attaching a hook or state to a prefab and trying to enter the prefab editor produces this warning in the console.

Prefab Mode in Play Mode was blocked by the script 'ArcadiaState' to prevent the script accidentally affecting Play Mode. See the documentation for [ExecuteInEditMode] and [ExecuteAlways] for info on how to make scripts compatible with Prefab Mode during Play Mode.
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

nasser avatar Dec 21 '18 00:12 nasser

Relevant documentation is ExecuteInEditMode and ExecuteAlways. ArcadiaState already has a ExecuteInEditMode attribute. From ExecuteInEditMode documentation:

This attribute is being phased out since it does not take Prefab Mode into account. If a Prefab with a MonoBehaviour with this attribute on is edited in Prefab Mode, and Play Mode is entered, the Editor will exit Prefab Mode to prevent accidental modifications to the Prefab caused by logic intended for Play Mode only.

From the ExecuteAlways documentation:

A MonoBehaviour using this attribute must ensure that they do not run Play logic that incorrectly modifies the object while in Edit Mode, or if the object is not part of the playing world. This can be done via Application.IsPlaying in which the script can pass in its own GameObject to check if it's part of the playing world.

If a MonoBehaviour runs Play logic in Play Mode and fails to check if its GameObject is part of the playing world, a Prefab being edited in Prefab Mode may incorrectly get modified and saved by logic intended only to be run as part of the game.

nasser avatar Dec 21 '18 16:12 nasser

Is there unwanted behavior beyond the warning in the console?

timsgardner avatar Jan 09 '19 04:01 timsgardner

I find these descriptions from the docs frustratingly imprecise, and don't see any others:

  • Update is only called when something in the Scene changed.
  • OnGUI is called when the Game view receives a non-editor-only Event that it does not use (e.g., EventType.ScrollWheel) and does not forward to the Editor's keyboard shortcut system (e.g., EventType.KeyDown, EventType.KeyUp). Events forwarded to the Game view are enqueued and are not guaranteed to be processed immediately.
  • OnRenderObject and the other rendering callback functions are called on every repaint of the Scene view or Game view.

timsgardner avatar Jan 09 '19 04:01 timsgardner