What is System.Action?

I am trying to put leaders boards into my game and I am trying to use Social.ReportScores, but for it’s parameters it asks for (score : Int64, board : String, callback : System.Action). I don’t know what the System.Action is. If any one knows what this is or knows how to use Social.ReportScores then I could really appreciate your help. I’ve been stuck on making leaderboards for about two months now.

An Action delegate is put simply an encapsulated method that returns no value, or a void encapsulated method. In this use case, it is acting as a call back that will fire off depending on what the type T is passed in for the System.Action, where T is a boolean variable.


Social.ReportScore (score, leaderboardID, success => {
        Debug.Log(success ? "Reported score successfully" : "Failed to report score");

as shown in the Unity doc’s above, the Debug.Log statement will print “Reported Score Successfully” if success = true, which is executed by the ReportScore method, or Debug.Log will print “Failed to report score” if success = false is set by ReportScore.

That essentially is what a “call back,” is, it’s calling your encapsulated method or bool upon completion. the => is a lambda expression, which is basically denoting you creating an anonymous method to pass as the callback, but you can still pass in a method if you wish as long as the method signature matches the type set by the Action, which is once again, a boolean. For example:

Social.ReportScore( score, leaderboardID, DidCallBackReturnTrue );

public void DidCallBackReturnTrue( bool isTrue )
    if( isTrue )
        Debug.Log( "Report Score successful" );
        Debug.Log( "Report Score failed" );

So, to put it in plain english, the ReportScore method is asking you what do you want to do in the case that ReportScore is successful, or ReportScore failed.

If this is still going over your head, which it may be as it’s admittedly a difficult concept to grasp as it was for me being a starter as well, this video may help from community member Prime31:

as with his delegates and events video that links to this.