- Home /
Problem with events
Hello, I have a problem where I've set up a simple event when google authenticates, like so:
public class GoogleStuff : MonoBehaviour {
public delegate void GoogleLogin();
public static event GoogleLogin OnGoogleLogin;
void OnEnable (){
PlayGamesPlatform.Activate();
PlayGamesPlatform.DebugLogEnabled = true;
}
void Awake () {
Social.Active.localUser.Authenticate ((bool success) => {
if(success){
Debug.Log("Authetication Success");
} else {
Debug.Log("Authetication Failed");
}
});
if(OnGoogleLogin != null){
print ("firing event");
OnGoogleLogin();
}
}
}
and I've subscribed an to the event with:
void OnEnable (){
GoogleStuff.OnGoogleLogin += ActivatePlayer;
}
void ActivatePlayer (){
print ("Event recieved");
UserName = Social.Active.localUser.userName;
LoadPlayerData ();
}
The ActivatePlayer function is not being called even though I'm getting the "fired event" log from the login. I assume I've done something wrong but I can't seem to find the right answer. Thanks for all the help.
~ Soos
Answer by troien · Jul 16, 2015 at 07:55 AM
I assume that with the "fired event" you mean the "firing event" event log?
Your problem though probably lies with the ExecutionOrder of the Unity Events. Awake is called before OnEnable. Which means that you fire the event and then after you fired it, you start listening (which means you'll never get the event). Renaming Awake to Start should fix this...
Your answer
![](https://koobas.hobune.stream/wayback/20220611231525im_/https://answers.unity.com/themes/thub/images/avi.jpg)