OnApplicationPause script orders

  1. Script A
  2. Script B

It’s have OnApplicationPause function.

I want to sort order OnApplicationPause Script A run before OnApplicationPause Script B when unpause game.

I setting script execution order but it’s not work for unpause game from background. It’s work when application open not background.

There are probably so many ways to achieve this.
Have a global script which references those scripts and has an OnApplicationPause method. Then you would call

ScriptA.MethodA();
ScriptB.OtherMethod();

Alternatively you could have a boolean to check whether the OnApplicationPause has run on the other script yet, if not, Invoke to check again in 0.2 seconds?.

I’m not sure if there’s a built-in way to control the callback ordering like that if Script Execution Order doesn’t do it.

But there’s several ways you can create your own order and dependencies. You can put an event on Script B, which Script A will listen for for instance:

public class ScriptA : MonoBehaviour {

    public ScriptB scriptB;

    private void Awake () {
        scriptB = FindObjectOfType<ScriptB>(); // get this reference in some way
        scriptB.OnPaused.AddListener(OnDependencyPaused);
    }

    private void OnDependencyPaused() {
        // do stuff
    }
}
public class ScriptB : MonoBehaviour {
    public UnityEvent OnPaused;
    public bool IsPaused { get; private set; }

    private void OnApplicationPause(bool pause) {
        IsPaused = pause;
        if(pause) {
            OnPaused.Invoke();
        }
    }
}