Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Help Wanted Clone prefab reference during runtime

Discussion in 'Prefabs' started by Goty-Metal, May 2, 2021.

  1. Goty-Metal

    Goty-Metal

    Joined:
    Apr 4, 2020
    Posts:
    168
    So i have a GameObject with references via inspector to some prefabs i instantiate during runtime, ex:
    Code (CSharp):
    1. public GameObject prefab1;
    2. public GameObject prefab2;
    ...

    What i need is to COPY those prefabs during runtime because i need to modify some of their params depending on the scene WITHOUT instantiating it, something like:

    Code (CSharp):
    1. public GameObject prefab1;
    2. public GameObject prefab1Clone;
    3.  
    4. void Start() {
    5.     prefab1Clone = prefab1.Clone();
    6. }
    So i can do something like:

    Code (CSharp):
    1. ...
    2. prefab1Clone.GetComponent<CircleCollider2D>().radius = newValue;
    ...without messing up the original prefab, otherwise changes persist.
    And no i can't instantiate the prefab and then instantiate from that copy because theyr'e pretty complex GameObjects and i'd mess all the scene if i instantiate them to have them just as reference...

    Thanks for the help!
     
  2. Goty-Metal

    Goty-Metal

    Joined:
    Apr 4, 2020
    Posts:
    168
    After 3+ weeks i'm still interested and trying to find a solution, but i start thinking it's not possible...
     
unityunity