- Home /
Unity crashes when using ExecuteAlways on a UIBehaviour
Hey,
because of some limitations with the existing AspectRatioFitter (not being able to set RectTransform anchors when using modes FitInParent
or EnvelopeParent
and thus requiring an extra wrapper object), I've written a custom AspectRatioFitter called AnchorAspectFitter. Like Unity's version, mine inherits from UIBehaviour
(and was implementing ILayoutSelfController
for a time).
All my script is doing, is making some calculations and then setting offsetMin
and offsetMax
of its RectTransform. Additionally, I'm using the DrivenRectTransformTracker
to block the associated RectTransform values in the editor. All code related to this is wrapped in #if UNITY_EDITOR
directives.
The function which does the above is called in the inherited functions OnEnable
and OnRectTransformDimensionsChange
. I've also written a custom inspector that calls this function in OnEnable
and when detecting changes in OnInspectorGUI
. Now, the issue this presents is that the layout is only updated outside of play mode, when the object gains focus in the inspector or is changed. So unlike Unity's AspectRatioFitter, the layout is not updated when some parent or the canvas is resized, the resolution is changed etc. A simple remedy should be to use the [ExecuteAlways]
or [ExecuteInEditMode]
attribute (like Unity's AspectRatioFitter does), but whenever I try this, dragging a parent RectTransform anchor or trying to open the PrefabView will cause Unity to freeze and crash.
Am I doing something terribly wrong here or is there a general issue when combining a custom UIBehaviour
with the ExecuteAlways
attribute? Should I report a bug?
Your answer
Follow this Question
Related Questions
Why doesn't childing a gameobject to GridLayoutGroup at runtime align it properly? 1 Answer
Display loaded UI Image in Container with native size 0 Answers
Content size fitter alignment issue 1 Answer
Issues with world space canvas for different resolutions. Any Workaround ? 0 Answers
Vertical Layout Group Not Behaving Even Close to Correctly 1 Answer