x


iTween Paths : Element with the same key already exists in the dictionary

I have a menu which is a duplicate of my main game scene with a flythrough camera.

I have a main game scene where I have several objects which follow iTweenPaths.

I have a duplicate of this scene, just without the player, with a camera flythrough for the main menu.

When the menu scene loads the game scene I get the following:

ArgumentException: An element with the same key already exists in the dictionary. System.Collections.Generic.Dictionary`2[System.String,iTweenPath].Add (System.String key, .iTweenPath value) iTweenPath.OnEnable () (at Assets/Plugins/iTweenPath.cs:17)

I understand the error, keys are unique and the paths are already added within the menu scene but I don't know how to correct it?

more ▼

asked Feb 23 '11 at 10:12 PM

MSFX gravatar image

MSFX
62 6 8 15

(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

Change blah.Add(key, value) to blah[key] = value;

The former throws an exception when adding a duplicate key, while the latter doesn't.

more ▼

answered Feb 23 '11 at 11:51 PM

Mike 3 gravatar image

Mike 3
30.7k 10 67 255

managed to work around it thanks :)

Feb 25 '11 at 10:20 AM MSFX
(comments are locked)
10|3000 characters needed characters left

Have you tried the most recent iTweenPath from my blog? If so can you send me a project that I can take a look at?

more ▼

answered Feb 24 '11 at 02:56 AM

pixelplacement gravatar image

pixelplacement
682 8

will send one later today, thanks bob

Feb 25 '11 at 10:20 AM MSFX
(comments are locked)
10|3000 characters needed characters left

Mike 3 has it right in general terms above.

The actual change to iTweenPath.cs that I made is:

    void OnEnable(){
    if(!paths.ContainsKey(pathName)){
       //paths.Add(pathName.ToLower(), this);
       paths[pathName.ToLower()] = this; // updated from http://answers.unity3d.com/questions/49137
    }
}

As you can see I commented out the original line and added the replacement line: paths[pathName.ToLower()] = this;

This fix works my situation when I was instantiating the same prefab from a spawn point multiple times. Hope this makes it easier for all.

Oz.

more ▼

answered Feb 23 '12 at 03:51 AM

TheOz gravatar image

TheOz
1 2 3 3

great solution!

Feb 14 at 11:52 PM aljndrrr
(comments are locked)
10|3000 characters needed characters left

Oh my god thanks guys so much for the easy fix.... Much appreciated...

more ▼

answered Oct 02 '12 at 04:28 PM

amaceika gravatar image

amaceika
1

Hi There. It's great that you found this information helpful. (but ...)

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

Happy Coding =]

Oct 02 '12 at 04:30 PM alucardj

sorry forgot about the comment button

Oct 02 '12 at 04:36 PM amaceika
(comments are locked)
10|3000 characters needed characters left

I added these lines before line 17 and I no longer get that error, Im moving the path nodes around in my script, and the changes were not taking effect when I loaded the scene, then left, and loaded the scene again. The 2 lines below are a quick fix, pixelplacement maybe you want to look into this?

    if(paths.ContainsKey(pathName.ToLower()))
        paths.Clear();

        paths.Add(pathName.ToLower(), this);
more ▼

answered Aug 10 '11 at 04:49 PM

JasonM gravatar image

JasonM
46 5 5 7

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x435
x176
x109
x57

asked: Feb 23 '11 at 10:12 PM

Seen: 2563 times

Last Updated: Feb 14 at 11:52 PM