Search Unity

[Solved]Action Delegate wont work

Discussion in 'General Discussion' started by grimjim, Oct 5, 2017.

  1. grimjim

    grimjim

    Joined:
    Jan 18, 2014
    Posts:
    17
    Hey, im using Unity 2017.1.0f3

    When i try to run this code
    Code (CSharp):
    1.    
    2.     public void testa()
    3.     {
    4.  
    5.     }
    6.  
    7.     private void testb()
    8.     {
    9.         abc(testa);
    10.     }
    11.  
    12.     private void abc(Action Callback)
    13.     {
    14.         Callback();
    15.     }
    i will get these errors

    abc(Action)' has some invalid arguments

    error CS1503: Argument `#1' cannot convert `method group' expression to type `Action'

    error CS0119: Expression denotes a `variable', where a `method group' was expected

    the exact code works in another project same unity version.

    Maybe someone have the same issue or a solution?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    What happens If you use System.Action instead of Action?
     
    grimjim likes this.
  3. grimjim

    grimjim

    Joined:
    Jan 18, 2014
    Posts:
    17
    will try in a min. but im using System
     
  4. grimjim

    grimjim

    Joined:
    Jan 18, 2014
    Posts:
    17
    Wow to be Honest that works xD but i cant imagine why
    Code (CSharp):
    1. using System;
    im using System lik that and it should work. i think it have todo something with the project because in another one it works without System.Action

    But thanks
     
  5. grimjim

    grimjim

    Joined:
    Jan 18, 2014
    Posts:
    17
    Ok got it was a bit Blind xD there is a Class named Action thats why