Search Issue Tracker

Fixed in 2019.2

Fixed in 2018.3, 2019.1

Votes

0

Found in

2018.3.0a6

2018.3.3f1

2019.1.0a1

2019.2.0a1

Issue ID

1123424

Regression

No

Prefab disappears from Prefab Mode when Setting Prefab parent with GameObject.Find

Scene Management

-

Reproduction Steps:
1. Open "SampleScene" in attached "TestBug.zip" project
2. Enter Prefab Mode by double-clicking on the "TestPrefab" in prefabs folder
3. Drag the "TestSetParent" script onto the prefab
4. Observe The Prefab Mode and Console

Expected Behavior: Script tries to look for the desired GameObject in Prefab Mode and if found sets it as a parent
Actual Behavior: Script finds the desired GameObject in the Scene and sets it as a parent, Prefab disappears from Prefab Mode

Reproducible with: 2018.3.5f1, 2019.1.0b2, 2019.2.0a4

Note: Could not test on 2017.4 stream as there is no Prefab Mode

-------------------------------------------------------------------------------------
Fixed in 2019.2.0a8

  1. Response avatar

    Resolution Note (fix version 2019.2):

    From 2018.3 using ExecuteInEditMode and ExecuteAlways logic needs to handle the special care:
    In this case you need to check what Stage the GameObject is in before reparenting. Make sure that the GameObject is in the Main Stage (and not a Prefab Stage) before reparenting. E.g:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor.SceneManagement;
    #endif

    [ExecuteInEditMode]
    public class TestSetParent : MonoBehaviour
    {
    private void OnEnable()
    {
    #if UNITY_EDITOR
    if (StageUtility.GetStageHandle(gameObject) == StageUtility.GetMainStageHandle())
    #endif
    transform.parent = GameObject.Find("TestContainer").transform;
    }
    }

    We have also added better error handling when the root GameObject in Prefab Mode is incorrectly been moved to another Stage (e.g the main scenes).

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.