Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How can I apply a child object of a prefab to another prefab serialized field

Discussion in 'Getting Started' started by devmaheswari2017, Oct 23, 2023.

  1. devmaheswari2017

    devmaheswari2017

    Joined:
    Oct 9, 2022
    Posts:
    8
    Hey everyone I always face issue with prefabs in unity and how unity doesn't allow me to override and apply all the changes to its other instances and this time I am facing kind of simple but weird issue where I have a MainMenu( a panel) prefab which has a button child object on it and another prefab SoundManager where I need that button child object reference so I can perform my logic like muting my sound and as I get the reference of the button child object from a local MainMenu prefab inside my hierarchy I couldn't do the override/Apply all thing on my SoundManager prefab and I don't think I can get the child object of my MainMenu prefab from prefab folder inside my project/assets so is there any solution where I can get the reference and still be able to apply it to all the other instances of my SoundManager prefab.

    Like I could thing of few things like making the child object a separate prefab or instead of getting refrence in soundmanager I could shift my logic from soundmanager to the MainMenu and then get the button reference but is there any other solution without changing or doing something unnecessary like this

    Please if u could enlighten me and help me

    thanks a lot for your help.
     
  2. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    I think the problem here is how you look at prefab. A prefab is a blueprint, not storage. When you make a copy from blueprint you need to put init data (if they change in time or they source). You can save/load this data to/from files (for regular data, int, strings, etc.), most common solution is some kind of static GameManager that exist all time in background (to connect references).
     
    Last edited: Oct 27, 2023