Skip to content

Instantly share code, notes, and snippets.

@mikelovesrobots
Created April 17, 2015 18:42
Show Gist options
  • Save mikelovesrobots/f8aeb8cc5ccb1b97bc61 to your computer and use it in GitHub Desktop.
Save mikelovesrobots/f8aeb8cc5ccb1b97bc61 to your computer and use it in GitHub Desktop.
ParseSafeInitializeBehaviour
using UnityEngine;
using System.Collections;
using Parse;
// Parse for Unity3d stops responding if it gets initialized twice
// or the original initialization goes away (e.g., you leave the scene)
// so use this instead of the regular ParseInitializeBehaviour, and
// throw it in every scene that you need to talk to Parse in
public class ParseSafeInitializeBehaviour : ParseInitializeBehaviour {
public static bool IsAlreadyAlive;
public override void Awake() {
if (IsAlreadyAlive) {
Destroy(gameObject);
return;
}
IsAlreadyAlive = true;
DontDestroyOnLoad(gameObject);
base.Awake();
}
}
@cita-moviles
Copy link

Thanks! It worked for us

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment