1
votes

I'm working on a 2D UI application with Unity and i have a problem. I was working on the script to instantiate my popup window (i made a prefab). And i succeed but later Unity crashed and i had to redo my scene (forgot to ctrl+s) Since this crash, my popup isn't instantiate as a child of my canvas and i've got this message: "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption"

Here is my script :

using UnityEngine;
using System.Collections;

public class Popup : MonoBehaviour
{
    public RectTransform popupPrefab;
    private Animator anim;

    // Use this for initialization
    void Start()
    {
        //get the animator component
        anim = popupPrefab.GetComponent<Animator>();
        //disable it on start to stop it from playing the default animation
        anim.enabled = false;
    }

    public void CreatePopup()
    {
        // Copie du prefab
        RectTransform newPopup = Instantiate(popupPrefab, popupPrefab.transform.position, popupPrefab.transform.rotation) as RectTransform;
        newPopup.transform.SetParent(transform, false);

        //anim = newPopup.GetComponent<Animator>();
        //anim.enabled = true;
        //anim.Play("Popup");
    }

    public void ClosePopup()
    {
        anim.enabled = true;
        anim.Play("ClosePopup");
    }
}

I don't understand why i have this error since it was working fine before crash...

if you have any idea Thanks

1
Yes sorry it's with UI object I create a full UI interface with canvas and UI toolsDane Girard
This is my actual code What do you mean ?Dane Girard
hi @danegirard. Please TICK an answer to help keep the board tidy.Fattie
Oh yes sorry I redo all my project from the beginning to make this error disappear...Dane Girard

1 Answers

-1
votes

I solved the problem by re-doing my project from the beginning...