Search Unity

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

Question Visual Scripting - Prefabs handling of object variables. Any solution?

Discussion in 'Authoring Dev Blitz Day 2023' started by Marou1, Jan 26, 2023.

  1. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    157
    Hi,

    If you have a prefab with these 2 variables:


    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:


    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 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
     
  2. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    157
    Hi,

    Is no answer means no solution or workaround?

    Thanks
     
  3. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    157
    Still waiting...
     
  4. asger60

    asger60

    Joined:
    Mar 27, 2013
    Posts:
    45
    we are currently having a similar issue. Did you ever find a solution?
     
  5. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    157
    The only workaround I found is to create a new game object for the specific variables, and even in some cases, 1 new game object for a new variable. Really not ideal, but at least the new game object will be created in all instances of the prefab with its the attached variable.