cancel
Showing results for 
Search instead for 
Did you mean: 

Dictionary and Collections

Michael_Butt1
Star Contributor
Star Contributor

I am working on a Unity Script that uses key-value pairs. I wrote my logic using vb.net in Visual Studio and used a Collection, however when I tried the same thing in the Unity Script editor, it does not understand what a Collection is. I tried using a Dictionary instead and can only get it to work if I use: System.Collections.Generic.  No matter what I use from there I can't get the Dictionary or any of the Collection options to work for me.

In Visual Studio, my code looked like this and allowed me to add key value pairs then loop through them to compare them to other values, none of which works in the Unity editor:

        Dim things As Collection = New Collection        things.Add("keyVal1", "something")

I also tried this in the Unity Editor after adding System.Collections.Generic:

        Dim things as New Dictionary(Of String, String)

using this, the code editor is not giving me the option to use ".add" or ".Contains" again both of which worked for Collections in visual studio.If it is letting me use ".add" the script editor is not showing it when i type. ".Contains" throws an error.

Any help as to where I'm going wrong here would be much appreciated.

5 REPLIES 5

Michael_Butt1
Star Contributor
Star Contributor

That's good to know, thanks Kyle.

for the record ListDictionary worked just fine in place of Collection. I didn't have to change any code other than the variable declaration.