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 /
avatar image
1
Question by falllout1998 · Apr 17, 2020 at 12:48 AM · ambiguous reference

vector3 is ambigous?

private Vector3 moveValues = Vector3.Zero;

im using the unity api example to write this

is it a problem I have with something in visual studio its between system numerics and unityengine

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Bunny83 · Apr 17, 2020 at 01:28 AM

Well this is the reason why we actually have namespaces. So we can have types with the same name not conflicting each other. Keep in mind that you don't have to put any "using" statement at the top of your script. A using statement is just a shortcut for your whole file. So when you "use" a namespace you essentially bring it's members into your local scope and you can directly use the types / classes in that namespace without having to write out the namespace everytime you use the type in your file.


However if you import / use two namespaces which both contain a certain type the compiler has no way to determine which of the two types you wanted to use. So since System.Numerics has a Vector3 struct and the UnityEngine namespace has one as well you have a conflict here.


There are several ways to solve this issue:

  • First of all get rid of one of the using statements. Usually the one that contains less things you need. In Unity it wouldn't make much sense to get rid of using UnityEngine; since you will need a lot different things from that namespace. Now if you want to use something from the System.Numeric namespace you iust have to use the fully qualified type name. So instead of XXXX you use System.Numerics.XXXX. That's what the compiler does under the hood anyways.

  • The second solution is to still keep both using statements and add a specific using alias for the Vector3 type as well. A type alias looks like this using Vector3 = UnityEngine.Vector3; This will tell the compiler when faced with "Vector3" in your code it will use the UnityEngine.Vector3 type.

  • Another solution would be to try to split your code into two seperate files where you can use different using statements. So the Unity related code will of course has it's using UnityEngine at the top and your other code that requires the System.Numerics namespace won't have the using UnityEngine statement. So this is more of an organisatorical approach.


Note that you get a similar issue when importing the UnitySngine and the System namespace. Both namespaces have a class called Random. If you import both you're in the same situation again. I would recommend to only using an alias if there's just one or max two conflicting classes. If there are more the other solutions are generally better. Many alias statements can make the code much harder to read.

Comment
Add comment · Show 1 · Share
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 falllout1998 · Apr 17, 2020 at 01:43 AM 0
Share

Thank you for this great answer!

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

124 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 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

Ambiguous Reference? 3 Answers

Ambigous Reference Animation 1 Answer

Ambiguous reference: how to fix ? -1 Answers

Ambiguous reference 'preview' 2 Answers

"Ambiguous Reference 'Label'" Errors, WebGL 1 Answer


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