Search Unity

Can you remove a GameObject from a parent prefab but keep it in a child?

Discussion in 'Prefabs' started by OtakuD, May 2, 2019.

  1. OtakuD

    OtakuD

    Joined:
    Apr 24, 2014
    Posts:
    49
    Hey Peeps, I saw that I can create a new base prefab by dragging the root object into the project window but I'm at a loss as to how I can now modify this base while leaving the last base as is?

    Is this possible through editing the prefab file manually?
     
  2. OleJuergensen

    OleJuergensen

    Joined:
    Mar 21, 2018
    Posts:
    11
    If I understand you correctly, you want to break the prefab link to your instance. I don't have the editor open right now, but that option is accessible via right click I think. Or underneath the gameObject menu of the editor.

    Cheers
     
  3. OtakuD

    OtakuD

    Joined:
    Apr 24, 2014
    Posts:
    49
    No, I would like to maintain the link. What I want to do is shift the gameobject "addition" entry point to the prefab after the current one, without removing the gameobject entirely and re-adding it up the hierarchy. Hopefully preserving all the other modifications done to this object down the line and not having to do them all again.
     
  4. OleJuergensen

    OleJuergensen

    Joined:
    Mar 21, 2018
    Posts:
    11
    Sorry, I really cannot follow. Care to provide an example? What setup do you start out with, and where do you want to end up?
     
  5. OtakuD

    OtakuD

    Joined:
    Apr 24, 2014
    Posts:
    49
    Ok as a simple example lets say I have a prefab with 2 GameObjects in it, A and B. Now I make this prefab a new base of itself (by dragging the root into the project window), effectively making a copy of this A+B prefab but linked to the original.

    A -> A
    B -> B

    Now I would like to take the base prefab and shift the GameObject B link up the hierarchy, so that the new base only has A in it, making B a new "addition/modification" to the child rather than a link.

    A -> A
    0 -> +B

    The reason why I want to do this is that B has many other modifications down the line in my prefab tree but I'd like to have a new base which doesn't have it in it while keeping the link to the prefabs in the tree.
     
  6. OleJuergensen

    OleJuergensen

    Joined:
    Mar 21, 2018
    Posts:
    11
    I think I got you now, but have no solution. You are talking about prefab variants. With instancing, variants and nesting there are so many similar concepts, that it's hard to talk about stuff sometimes :D
    I hope I got you right this time: You want to have the "B" child to be removed from the base, but not from the variant. So that variants of the variant can still refer to it. You want to move the gameObject B entirely from the base to the variant while keeping the ID.
    I think it is not possible in the editor, but when you mess with the prefab files it should work somehow. Unfortunately, I could not figure out how, because the fileIDs are confusing:

    - I have a prefab called "root" with two children "A" and "B"
    - I have a variant of "root" called "variant". No modifications.
    - I have a variant of "variant" called "variant 2". It adds a BoxCollider to "B".

    In the .prefab files, there must be some link from the BoxCollider to the original "B" gameObject, right? It must be linked by ID's somehow, but I cannot find the trace back. The file "variant 2.prefab" says a BoxCollider is added to a gameObject with a CorrespondingSourceObject ID that I cannot find in "variant.prefab" nor "root.prefab". So that's weird. Without understanding how this works, I cannot figure out how to accomplish what you want. If you can, I would be very interested.
     
    OtakuD likes this.
  7. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I have the same question. I managed to turn an existing prefab into a variant of a freshly created prefab, but now they have the same data. I would now like to remove child GameObjects and components from the new base without losing them on the variant, but it looks like this is impossible.