Search Unity

Losing Prefab Reference when Duplicate it

Discussion in 'Immediate Mode GUI (IMGUI)' started by Martin_Gonzalez, Jul 15, 2016.

  1. Martin_Gonzalez

    Martin_Gonzalez

    Joined:
    Mar 25, 2012
    Posts:
    361
    Hi everyone!
    I just want to ask if anybody know why this is happening:

    Via a editor script i create a prefab with an empty as a parent and i attach to it (the empty) another custom editor script. When i create the object y call a method passing the prefab reference so i have a button in the object that is called "Select" and it select the prefab on the project tab.
    I have a button that is called "Duplicate" which logic is destroying and creating a new prefab with the exact transform but when i duplicate it using ctrl + D i lose the reference of the prefab, so when i click in Select of the duplicated item its null.

    Is there a way to listen when an item is duplicated or maintaining the references?

    Thanks a lot!
     
  2. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    Hey there,

    Take a look at Prefab Utility, I am going to assume you are just copying like you would in play mode. If you want to keep prefab references you must use that class.

    Cheers,
    Byron
     
  3. Martin_Gonzalez

    Martin_Gonzalez

    Joined:
    Mar 25, 2012
    Posts:
    361
    No, the problem is that i have an empty GO (Grey) with a prefab inside(blue). The empty GO has a variable referencing the prefab so when i duplicate it using control + D, the script of the duplicated GO lose the reference of his own prefab, my problem is that i dont have control over the duplicate shortcut, so what i'm thinking is that i have to find in the start of my mono the reference of my prefab, i have to figure it out.