Skip to content

Instantly share code, notes, and snippets.

@mikelovesrobots
Created April 17, 2015 18:41
Show Gist options
  • Save mikelovesrobots/274b40c23d64a09d58c3 to your computer and use it in GitHub Desktop.
Save mikelovesrobots/274b40c23d64a09d58c3 to your computer and use it in GitHub Desktop.
ParseSafeInitializeBehaviour
using UnityEngine;
using System.Collections;
using Parse;
// Parse 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 access Parse from
public class ParseSafeInitializeBehaviour : ParseInitializeBehaviour {
public static bool IsAlreadyAlive;
public override void Awake() {
if (IsAlreadyAlive) {
Destroy(gameObject);
return;
}
IsAlreadyAlive = true;
DontDestroyOnLoad(gameObject);
base.Awake();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment