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 Griffo · Jun 05, 2012 at 07:27 PM · stringvoid

Cannot convert void to String

In the below script I get the message " Cannot convert void to String " on line 5, I'm trying to link to a script called mouseSoundCntrl that holds the SwingSound I'm after, I've got lots more sounds on there and I can call them just by using something like this - mouseSoundCntrl.MouseWalkSound(); the problem is putting it in the animation event it comes back with that error, any help please would be great fully appreciated, Thanks.

 else if(_characterState == CharacterState.Swing) {
         
 // Create and set up the AnimationEvent
     var swooshSoundEvent = new AnimationEvent();
         swooshSoundEvent.functionName = mouseSoundCntrl.SwingSound();
             swooshSoundEvent.time = 0.5;
         
         _animation[swingAnimation.name].layer = 1; // Place the Swing animation on a higher level
         _animation[swingAnimation.name].clip.AddEvent(swooshSoundEvent); // Add the event to an AnimationClip
         _animation[swingAnimation.name].blendMode = AnimationBlendMode.Additive; // set the blend mode to Additive so it will blend
                                                                                 // into whatever animation is playing when it's called
         _animation[swingAnimation.name].wrapMode = WrapMode.Once;
         _animation.CrossFade(swingAnimation.name); // Play the Swing animation
         
         }
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 kolban · Jun 05, 2012 at 08:05 PM

You have a line which reads:

 swooshSoundEvent.functionName = mouseSoundCntrl.SwingSound();

The functionName property of an AnimationEvent object is of type "String". This property is set to be the String name of a function that you want to be called. I suspect what you really want is:

 swooshSoundEvent.functionName = "SwingSound";

What this will do is perform a SendMessage("SwingSound") when the animation event is fired. See:

http://unity3d.com/support/documentation/ScriptReference/AnimationEvent-functionName.html

Comment
Add comment · Show 2 · 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 Griffo · Jun 05, 2012 at 08:43 PM 0
Share

Thanks for the information, but the "SwingSound" is in another script so I'm trying to call it through "mouseSoundCntrl" a link to the script "$$anonymous$$ouseSoundController" that holds the sound files.

avatar image kolban · Jun 05, 2012 at 10:08 PM 0
Share

When an Animation event fires as a result of a frame being reached, the Send$$anonymous$$essage() mechanism is utilized to find a named function (supplied as a String). This means that you need to study Send$$anonymous$$essage().

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

returning a variable in javascript 1 Answer

How to convert a 'string' to the name of a 'void' function? 1 Answer

Calling a void from another script Unexpected "String" 1 Answer

JSON Saving/loading " error CS0029: Cannot implicitly convert type 'void' to 'string' " 1 Answer

How to call a variable using a String for the variable name? 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