Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Demigiant · Jul 10, 2014 at 03:27 PM · c#coloroverload

Vector4 and Color messing up with method overloading

Hello,

it's very hot here, and I can't seem to understand if my issue has a solution or not.

I have a method which accepts a parameter of type Color:

 void SomeMethod(Color color) {...}

Now the problem is that I really really need to overload that method, so that it can alternatively accept a Vector4 parameter instead and do different things:

 void SomeMethod(Vector4 vector) {...}

Now that's where things get bad, since Unity's Color type can be implicitly converted to Vector4 and viceversa, so the compiler doesn't know which one to choose. Anyone knows if there's some tricky solution to this issue, while still being able to overload?

Thanks

EDIT ------------------------

tswalk showed me that it SHOULD work, so I made other tests and realized the issue is still related to overloads and implicit casting, but happens only when there are optional parameters involved. Posted an updated question here

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
2
Best Answer

Answer by tswalk · Jul 10, 2014 at 03:39 PM

did you try casting the type to the overloaded method to see if it would get the right signature?

public void testMethod(Color color) { Debug.Log("color method"); }

public void testMethod(Vector4 _vector) { Debug.Log("vector method"); }

 Vector4 test = new Vector4(0, 0, 0, 0);
 Color cTest = Color.black;

 testMethod((Vector4)test);
 testMethod((Color)cTest);
 testMethod(test);
 testMethod(cTest);



In both sets of examples above, the correct method is called for me.... so, not sure why the signature isn't working for you.

Comment
Add comment · Show 4 · 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 Demigiant · Jul 10, 2014 at 03:53 PM 1
Share

This is weird, I have no issue with the replica of your example. Let me investigate a little more and I'll come back at you. In the meantime thanks a lot for the heads-up :)

avatar image tswalk · Jul 10, 2014 at 03:55 PM 0
Share

no problem, i'm not an "expert" coder.. but perhaps if you posted a bit more code on the methods signatures and how you call them it may help.. perhaps it's just a typo :)

avatar image Demigiant · Jul 10, 2014 at 04:06 PM 0
Share

Yup I should've posted more code, sorry, but I thought the problem was language-based. Ins$$anonymous$$d apparently it's Unity/$$anonymous$$ono based. I'm gonna post a new question now with my new findings and redirect you there, in case you have something :)

avatar image Demigiant · Jul 10, 2014 at 04:18 PM 0
Share

Posted an updated question here: http://answers.unity3d.com/questions/745362/method-overloading-fails-with-implicit-typecasting.html

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

22 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Method overloading fails with implicit typecasting and optional parameters 0 Answers

Transitioning colors based on variable. 1 Answer

How to change a buttons color? 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