Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: wallaceb68 on February 27, 2014, 02:49:46 PM

Title: donot destroy/ destroy duplicate
Post 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);
        }
    }
Title: Re: donot destroy/ destroy duplicate
Post by: jeanfabre on March 04, 2014, 06:53:57 AM
Hi,

 What is it meant to achieve? Is it this singleton issues with level loading?

bye,

 Jean
Title: Re: donot destroy/ destroy duplicate
Post by: Marsh on March 09, 2014, 09:50:59 PM
Code: [Select]
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 ();
}
}
}
Title: Re: donot destroy/ destroy duplicate
Post by: jeanfabre on March 11, 2014, 07:27:31 AM
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
Title: Re: donot destroy/ destroy duplicate
Post by: Marsh on March 11, 2014, 09:10:55 AM
Fixed up the Tooltip and removed the Debug.Log I made this in a hurry.
Title: Re: donot destroy/ destroy duplicate
Post by: jeanfabre on March 12, 2014, 04:44:56 AM
Hi,

 thanks :)

bye,

Jean