• 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
3
Question by Essential · Nov 27, 2014 at 07:01 PM · c#event4.6argumentexception

ArgumentException: method return type is incompatible

I'm sending an integer via a UI button event in 4.6 to this (simplified) function and it's giving me a runtime error. Any ideas what I'm doing wrong?

    public IEnumerator ChangeScreen ( int newScreen )
     {
         yield return null;
     }

Full error looks like this:

ArgumentException: method return type is incompatible System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Delegate.cs:190) System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Delegate.cs:276) UnityEngine.Events.InvokableCall`1[System.Int32]..ctor (System.Object target, System.Reflection.MethodInfo theFunction) UnityEngine.Events.CachedInvokableCall`1[System.Int32]..ctor (UnityEngine.Object target, System.Reflection.MethodInfo theFunction, Int32 argument) UnityEngine.Events.PersistentCall.GetRuntimeCall (UnityEngine.Events.UnityEventBase theEvent) UnityEngine.Events.PersistentCallGroup.Initialize (UnityEngine.Events.InvokableCallList invokableList, UnityEngine.Events.UnityEventBase unityEventBase) UnityEngine.Events.UnityEventBase.RebuildPersistentCallsIfNeeded () UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) UnityEngine.Events.UnityEvent.Invoke () UnityEngine.UI.Button.Press () (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/Button.cs:36) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/Button.cs:45) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/ExecuteEvents.cs:52) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.EventSystem:Update()

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

2 Replies

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

Answer by Essential · Nov 27, 2014 at 07:31 PM

I think it is because I have set the function to be IEnumerator and the event system can only call non-returnable functions.

It's a bit of a bug. An IEnumerator method won't show up as a possible choice in the event properties, but if you begin it as void, select it in the event list, then change its type in the script later, it'll still be chosen in the event properties and that's when you start getting errors.

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 Bodhi1Kanobi · Dec 17, 2014 at 08:43 AM 0
Share

I am having a similar issue, I am using a static Co-routine Utility function in a seperate C# script as an alternative to "yield WaitForSeconds()" in a javascript for a UI controller. I Am doing this as the standard timescale is 0 and need to work around that, but I am having no luck either.

avatar image alone1992 · May 24, 2015 at 08:13 AM 0
Share

Yes its Best answer , I think we could do it by a parallel function with event function , that activated by simple Boolean and do all of operation in that function ins$$anonymous$$d of event function

avatar image
4

Answer by mikolo · Jan 30, 2015 at 03:37 PM

i have a solution of the yield Problem. Unity Version 4.6.1

public IEnumerator ChangeScreen ( int newScreen ) { test();

}

function test() { yield return null; }

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 ChaseCEO · Dec 31, 2015 at 07:33 AM 1
Share

What worked for me was

 public void NextLevel(String name){
     //do something
     float somethingTakes = 2f;
     WaitForSecondsDo(somethingTakes);// 2f = 2 seconds.
     Scene$$anonymous$$anager.LoadScene(name);
 }
 
 IEnumerator WaitForSecondsDo(float secToWait){
     yield return new WaitForSeconds(secToWait);
 }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

28 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

Related Questions

Multiple Cars not working 1 Answer

passing function to class 0 Answers

Distribute terrain in zones 3 Answers

When I pause my game and enable canvas and then resume my keyboard starts controlling the menu... 1 Answer

passing function to class 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