Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

IL2CPP does not support marshaling delegates that point to instance methods to native code

Discussion in 'iOS and tvOS' started by MAWMatt, May 14, 2020.

  1. MAWMatt

    MAWMatt

    Joined:
    Nov 10, 2016
    Posts:
    77
    Hi folks,

    I'm using a plugin to get a secure Game Center login, when I attempt to run through the process I get the error in the title.

    My call to start the process looks like this:
    Code (CSharp):
    1. GenerateSignature( ( signature, key, salt, timestamp ) =>
    2. {
    3.     if( !string.IsNullOrEmpty( signature ) )
    4.     {
    5.         PlayFabClientAPI.LinkGameCenterAccount( new LinkGameCenterAccountRequest()
    6.         {
    7.             GameCenterId = Social.localUser.id,
    8.             Signature = signature,
    9.             PublicKeyUrl = key,
    10.             Salt = salt,
    11.             Timestamp = timestamp.ToString(),
    12.             ForceLink = false
    13.         },
    14.         ( result ) =>
    15.         {
    16.             m_AccountsLinked[ ( int )AccountType.Platform ] = true;
    17.             callback?.Invoke();
    18.         },
    19.         ( error ) => { ProcessLinkError( AccountType.Platform, error.Error, callback ); } );
    20.     }
    21.     else callback?.Invoke();
    22. } );
    I then make the call to the plugin and catch the results with the following code:
    Code (CSharp):
    1. #if UNITY_IOS
    2. void GenerateSignature( SignatureDelegate callback )
    3. {
    4.     if( callback != null )
    5.         m_SignatureCallbacks += callback;
    6.  
    7.     GameCenterSignature.Generate( SignatureSucceeded, SignatureFailed );
    8. }
    9.  
    10. [MonoPInvokeCallback( typeof( GameCenterSignature.OnSucceeded ) )]
    11. void SignatureSucceeded( string publicKeyUrl, ulong timeStamp, string signature, string salt, string playerId, string alias, string bundleId )
    12. {
    13.     if( m_SignatureCallbacks != null )
    14.     {
    15.         m_SignatureCallbacks?.Invoke( signature, publicKeyUrl, salt, timeStamp );
    16.         m_SignatureCallbacks = null;
    17.     }
    18. }
    19.  
    20. [MonoPInvokeCallback( typeof( GameCenterSignature.OnFailed ) )]
    21. void SignatureFailed( string error )
    22. {
    23.     if( m_SignatureCallbacks != null )
    24.     {
    25.         m_SignatureCallbacks?.Invoke( string.Empty, string.Empty, string.Empty, 0 );
    26.         m_SignatureCallbacks = null;
    27.     }
    28. }
    29. #endif
    Can anyone explain to me which function/delegate is the problem and how I should go about fixing it?

    I really appreciate the help! Thanks!
    -Matt
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Which version of Unity are you using? In newer versions, this error message should include the name of the method causing the problem, so that might help to debug it.

    It looks like SignatureSucceeded and SignatureFailed are likely the issue though. Those are instance methods, but IL2CPP can only marshal delegates for static methods.
     
    ShantiB95 and CleverAI like this.
  3. MAWMatt

    MAWMatt

    Joined:
    Nov 10, 2016
    Posts:
    77
    I'm using Unity 2018.4, and I do see what you mean. The full error looks like:

    Code (CSharp):
    1. NotSupportedException: IL2CPP does not support marshaling delegates that point to instance methods to native code.
    2.  
    3.   at Online.GameCenterSignature.Generate (Online.GameCenterSignature+OnSucceeded OnSucceeded, Online.GameCenterSignature+OnFailed OnFailed) [0x00000] in <00000000000000000000000000000000>:0
    4.  
    5.   at SocialManager+<>c.<LogIntoAccount>b__16_0 (System.Boolean success) [0x00000] in <00000000000000000000000000000000>:0
    6.  
    7.   at UnityEngine.SocialPlatforms.GameCenter.GameCenterPlatform.AuthenticateCallbackWrapper (System.Int32 result, System.String error) [0x00000] in <00000000000000000000000000000000>:0
    So does that mean I can simply make those two functions static and it'll work?

    EDIT: That fixed it...just setting those functions to static worked!

    Thanks for the help!
    -Matt
     
    Last edited: May 14, 2020
    ShantiB95, CleverAI and JoshPeterson like this.