IsUnique - Last If statment issues

Below is my code. The last if statement doesn’t seem to function correctly for me and I cant work out why. If I run it commented out as below, I can duplicate an enemy in scene and get a GUID generated and it will stay between scenes. If I uncomment and run the full IsUnique, each enemy then duplicated shares the same GUID. Can any one see what is wrong.

private bool IsUnique(string candidate) {

            //checks key exists in dictionary
            if (!globalLookup.ContainsKey(candidate)) {

                return true;
            }

            //checks not pointing to ourselves 
            if (globalLookup[candidate] == this) {

                return true;
            }

            //if deleted then remove from dictionary
            if (globalLookup[candidate] == null) {

                globalLookup.Remove(candidate);
                return true;
            }

            //if (globalLookup[candidate].GetUniqueIdetifier() != candidate) {
            //
            //    globalLookup.Remove(candidate);
            //    return true;
            //}

            return false;
        }

cheers

Hmmm… I’m not sure what’s going on here… it appears to be exactly like the course code, and interestingly enough, I was able to duplicate enemies over and over and get a new UUID every time, with or without the last if statement commented out.

In any event, I ran through the logic manually, and it would seem the ideal solution would be to not have the final check. We’ve determined that the key does not exist, and that if it does exist that it’s not this entity or null. If it gets by these checks, then the key is not unique, and should return false. If it’s causing this issue, I’d just leave it out.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms