Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ritoban · Apr 13, 2017 at 02:46 AM · debuggingdictionaryvector3 operations

Dictionary ContainsKey not working with Vector3s?

The screenshot summarizes my problem. I have a Vector3 array corners, which is initialized as six distinct positions (which happen to be the WorldPositions of a Hexagons vertices). I also have a Dictionary Corners. For now, the HexCorner class is irrelevant. After assigning the corners to the array (which has length 6), I iterate i 0 to 6. What I am doing inside the loop can be seen in the image. In summary, if the corner has already been added, I set the value in the hexCorners array (an array of HexCorners] to be the value in the dictionary. Otherwise, I create a new HexCorner, assign it to the hexCorners array, and add it to the dictionary. This was not giving me the expected results (I noticed that there appeared to be duplicates in the dictionary, but I wasn't getting any errors).

After debugging, I saw this following bewildering thing in the watches. the Corners.Keys obviously contains the value of corners[i] (both of which are visible in the watches as the same value). However, Corners.ContainsKey(corners[i]) returns false, and the if statement in the code has been skipped over (excluding an unusual green arrow).

I suspect the problem has something to do with Vector3s being structs (but I assumed that they worked in Dictionaries). Note that I am not getting any errors when I try to add the values to the dictionary, and they do show up as duplicates in the watches.

Let me know if there's anything else you want me to post.

a screenshot with my problem

untitled.png (236.5 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Scribe · Apr 13, 2017 at 10:48 AM 0
Share

if one is (-34.64, ...) and the other is (-34.63, ...) they won't be considered equal but their toString methods will print the same output, the default equals is true if the magnitude of their difference is less than 1e-5. If that is too accurate, you could give your dictionary a custom implementation of IEqualityComparer<Vector3>

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

99 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

breakpoints stopped working 1 Answer

Text box not displaying a character split string generated at runtime 0 Answers

DEVELOPMENT_BUILD is not set in the Editor but works in device running 0 Answers

Unity Player Rendering Different in Development Mode vs Non-Development Mode 0 Answers

Traffic Light State Machine Dictionary Issues 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges