Search Unity

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

Question Dictionary Problem: Values copy each other

Discussion in 'Visual Scripting' started by SkullKing, May 20, 2021.

  1. SkullKing

    SkullKing

    Joined:
    May 31, 2012
    Posts:
    40
    I created a dictionary of lists, however when I try to fill the lists, the value of one list is instantly copied to the others like this:

    https://imgur.com/KH35F5m

    I created the top dictionary the same way as the lower one, but whenever I try to change a value in the top one, it instantly changes for every list in the dictionary. The lower one works fine.

    I tried to create another one to test this, but got an error as below:

    https://imgur.com/tVOc3yJ
     
  2. tigme

    tigme

    Joined:
    Jul 1, 2014
    Posts:
    37
    Never saw this before. Also working with lists and dictionaries. Getting to the point where I may need to do what you ar trying. I'll keep it in mind and post a resolution if I run into the same problem.
     
  3. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,012
    Try creating a new collection instance before setting its values in the graph.

    upload_2021-5-22_16-37-1.png
     
  4. SkullKing

    SkullKing

    Joined:
    May 31, 2012
    Posts:
    40
    The dictionary am using is not created at run time, I need it to be something that I can manually fill before the program runs.
     
  5. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,012
    In that case for lists there's new AotList (c) that takes an existing collection as an input:
    upload_2021-5-23_14-9-42.png

    For dictionaries I use this workaround to avoid any weird dictionary linking:
    upload_2021-5-23_14-8-50.png

    Although these days I use Odin Inspector's serializable dictionaries in scriptable objects. Much nicer than Bolt's/ Unity VS AoT dictionaries.