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 chronicfail · Aug 10, 2013 at 09:51 AM · functiondamagesendmessageoverload

Overloaded functions fail to call

I am testing new damage functions which will allow headshots and explosion knockback etc, by using multiple versions of the damage function with different parameters, so not all damaging items have to find all the parameters if it's not needed, and so they can use SendMessage instead of directly calling a function.

I am testing it with this code:

 function Damage () {
 print("damage, no parameters");
 }
 
 function Damage (damage : float) {
 print("damage, amount given: "+damage+" no other info");
 }
 
 function Damage (damage : float,type : DamageType){
 var typeName="Unknown";
 if(type==DamageType.RayBullet)
 typeName="Raycast Weapon";
 if(type==DamageType.RealBullet)
 typeName="Bullet Weapon";
 if(type==DamageType.Melee)
 typeName="Melee";
 if(type==DamageType.Explosive)
 typeName="Explosive";
 if(type==DamageType.Collide)
 typeName="Collision";
 if(type==DamageType.Splatter)
 typeName="Splatter";
 if(type==DamageType.Guardians)
 typeName="Guardians";
 print("damage, amount and type :"+damage+", "+typeName);
 }
 
 function Damage (damage : float,type : DamageType,hitCollider : Collider){
 var typeName="Unknown";
 if(type==DamageType.RayBullet)
 typeName="Raycast Weapon";
 if(type==DamageType.RealBullet)
 typeName="Bullet Weapon";
 if(type==DamageType.Melee)
 typeName="Melee";
 if(type==DamageType.Explosive)
 typeName="Explosive";
 if(type==DamageType.Collide)
 typeName="Collision";
 if(type==DamageType.Splatter)
 typeName="Splatter";
 if(type==DamageType.Guardians)
 typeName="Guardians";
 print("you just recieved "+typeName+" damage on "+hitCollider.ToString()+". You took this much damage: "+damage);
 }

but when using a SendMessage that sends a float damage amount, the no paramteter version is called, and it returns this error: "Failed to call function Damage of class PlayerRigidController Calling function Damage with 1 parameter but the function requires 3." The two parameter version seems to work though, so I don't know what is going on.

Please could someone help me fix this?

Comment
Add comment · Show 2
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 Jamora · Aug 10, 2013 at 09:58 AM 1
Share

How are you calling the 1 parameter version? $$anonymous$$aybe you're using an int and UnityScript doesn't (know how to) convert that.

avatar image chronicfail · Aug 10, 2013 at 10:25 AM 0
Share

It's a definite float, as it uses AnimationCurve.Evaluate multiplied by a float to work out the damage at a certain distance from the player

1 Reply

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

Answer by ArkaneX · Aug 10, 2013 at 10:24 AM

It seems SendMessage does not support overloads. There are some other questions, e.g. here related to this issue.

As a solution, you could create a method with one parameter, a class or struct with three properties - Damage, Type, HitCollider.

Comment
Add comment · Show 5 · 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 chronicfail · Aug 10, 2013 at 10:36 AM 0
Share

I changed the muliple parameter versions names to Damage1 to seperate them from the Damage function (now only the (damage : float) version), but although it works as it should, it still gives the exact same error. It's an improvement though because before it was calling the complete wrong function.

avatar image ArkaneX · Aug 10, 2013 at 10:49 AM 1
Share

Do I understand correctly, that after changing overload with 3 parameters to new method Damage1, and calling method Damage you still get "[...] with 1 parameter but the function requires 3" error? If yes, then I believe you're somehow still using the previously compiled dll.

avatar image chronicfail · Aug 10, 2013 at 10:52 AM 0
Share

So it's a problem with the software taing time to catch up, not with my code? I will try restarting unity, I think I have had issues like that before.

avatar image chronicfail · Aug 10, 2013 at 10:53 AM 0
Share

Still happens, but it's working anyway, so I'm not going to worry about that error any more unless it starts breaking things.

avatar image ArkaneX · Aug 10, 2013 at 10:59 AM 0
Share

I don't understand how it can work if the error still occurs... Anyway - if you need more investigation, leave a comment :)

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

16 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

Related Questions

Damage sending with grenades. 1 Answer

What is the best way to call a function from another script 1 Answer

How can I delay dealing damage? 1 Answer

SendMessage is working but the variable is not being updated on the other end 1 Answer

Sending a message from javascript to C# 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