Search Issue Tracker

Fixed in 2017.1

Votes

10

Found in

5.5.2p4

Issue ID

895722

Regression

Yes

Error when creating a RectTransform component in an Awake call of an instantiated MonoBehaviour

UI

-

When using an Awake call in an instantiated prefab during play mode, to instantiate another gameObject and attach a RectTransform, the program throws an error saying that it can't add RectTransform because a Transform is already attached.

Steps to reproduce:
1.Open attached project.
2.Run play mode.

The issue appears only in the Awake() calls of the instantiated prefabs. Even when using the suggested "var go = new GameObject("Canvas", typeof(RectTransform));" workaround proves to be ineffective.

Expected outcome: When the prefabs are created, their awake scripts create gameObjects with rectTransforms attached.
Actual outcome: The original Awake() call functions normally, but the second awake() calls made in the instantiated objects are thrown.

Reproduces on v. 5.5.2p4, 5.6.0f2, 2017,1,0a4

Doesn't reproduce on v. 5.5.1p4

Sidenote:
Similar issue reported here. Probably caused by the same thing.
https://issuetracker.unity3d.com/issues/editor-crashes-when-adding-text-component-to-game-object-in-play-mode-via-the-script

Comments (4)

  1. 201f9c130c6a79e7b272dc2933e5f45b?d=mm

    martaaay

    Apr 16, 2017 20:26

    I see this in my iOS build (but not the editor) even with the workaround. Using unity 5.5.3f1. Please reopen this bug as the known workarounds may not be sufficient.

  2. D42bd840b5fc0967b1aabd7190597ec5?d=mm

    SugoiDev

    Apr 10, 2017 02:24

    Reproduces in 5.5.3p1.

    For the time being, a workaround would be to create a template prefab with a RectTransform and instantiate it instead of constructing a GameObject.

  3. Ad96edfc21850b579a65d5f66bbae7a8?d=mm

    DMinsky

    Mar 31, 2017 17:01

    Reproduces on v. 5.5.3f1.

  4. 450b96fd74cbc40d7b2649b9ed0b7a56?d=mm

    HarryCodder

    Mar 28, 2017 12:28

    Doesn't reproduce on v. 5.5.2f1.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.