Search Unity

Question Issue with the prefabs handling object variables. Any solution?

Discussion in 'Visual Scripting' started by Marou1, Dec 6, 2022.

  1. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    161
    Hi,

    If you have a prefab with these 2 variables:
    upload_2022-12-6_9-29-49.png

    PrefabID does not change because it is the ID of the prefab.
    But SpecificValue will be different for each instance of the prefab in the environment.

    Let's say I place 50 instances and I set their SpecificValue to different values.

    Then I figure out that I need to add a new variable in the prefab:
    upload_2022-12-6_9-41-47.png

    The NewVariable will not be inherited by 50 the instances. It seems that the link of the Variables component with the prefab is broken because the value of one variable was changed.

    So I see 2 ways to handle this, and both are very tedious:
    1- Going through the 50 instances, reverting the Variables component and setting again the SpecificValue.
    2-Going through the 50 instances and adding the NewVariable.

    I tried a 3rd possibility, but it does not work. In the prefab, I created a second Variables component.
    The idea was to put all the variables that will not be modified in the first component (the link with the prefab will not be broken), and the variables that need to be specific to the instance, in the second component.
    So at least, if I need to add a new variable that is not specific to the instance, I could add it in the first component and it will be inherited by all the 50 instances.

    However, all the variables that are in the second component are ignored by the scripts and I get an error saying that these variables were not found, even though they are there in inspector.

    Any solution/workaround to handle this?

    Thanks
     

    Attached Files:

  2. C_Larsson

    C_Larsson

    Joined:
    Jun 27, 2022
    Posts:
    8
    Any luck finding a workaround? This is driving me nuts.
     
  3. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    161
    The only way I found is to create a new game object with a Variables component for the new variable.
    The new game object will be inherited by all instances with its variable.
    Obviously this is not a good solution so I used it only when necessary.
     
    C_Larsson likes this.