Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do I use NativeMultiHashMap?

Discussion in 'Entity Component System' started by MintTree117, Mar 6, 2020.

  1. MintTree117

    MintTree117

    Joined:
    Dec 2, 2018
    Posts:
    340
    How do I add multiple values to a key, and how do I get or loop over multiple values. And why is there no proper documentation on this? The documentation doesn't even state what the methods do, and there are no examples.
     
    Last edited: Mar 6, 2020
  2. Curlyone

    Curlyone

    Joined:
    Mar 15, 2018
    Posts:
    41
    Hi

    You can simply use Add function to add your value to a key, if key exists then your value will be added to that key's values. if key does not exist a new key will be created and value will be added to that key's values.

    You can iterate over given key's values with GetValuesForKey function and iterate over returned Enumarator.

    Something like this:

    Code (CSharp):
    1.         var values = relation.GetValuesForKey(key);  
    2.      
    3.         while (values.MoveNext())
    4.         {
    5.             var current = values .Current;
    6.         }
    you can use GetUniqueKeyArray method to key array,
     
  3. MintTree117

    MintTree117

    Joined:
    Dec 2, 2018
    Posts:
    340
    Thank you.