Playmaker Forum
PlayMaker Feedback => Action Requests => Topic started by: wallaceb68 on February 27, 2014, 02:49:46 PM
-
can this be made into an action?
public void Awake()
{
DontDestroyOnLoad(this);
if (FindObjectsOfType(GetType()).Length > 1)
{
Destroy(gameObject);
}
}
-
Hi,
What is it meant to achieve? Is it this singleton issues with level loading?
bye,
Jean
-
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Mighty Professional")]
[Tooltip("Dont Destroy on Load and Destroy Duplicates")]
public class Singleton : FsmStateAction
{
[Tooltip("The Game Object to check for duplicates with")]
public FsmGameObject go;
public override void OnEnter() {
Object.DontDestroyOnLoad (go.Value);
if (GameObject.FindObjectsOfType(go.Value.GetType()).Length > 1)
{
Object.Destroy(go.Value);
}
Finish ();
}
}
}
-
Hi,
Thanks for this, be careful with this on large scenes, finding objects without filtering them is very demanding and could be problematic on mobile distribution.
You should clean up the debug log and the tooltip for the action to be clear and clean.
Bye,
Jean
-
Fixed up the Tooltip and removed the Debug.Log I made this in a hurry.
-
Hi,
thanks :)
bye,
Jean