playMaker

Author Topic: donot destroy/ destroy duplicate  (Read 3836 times)

wallaceb68

  • Junior Playmaker
  • **
  • Posts: 87
donot destroy/ destroy duplicate
« 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);
        }
    }
« Last Edit: February 27, 2014, 02:52:50 PM by wallaceb68 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: donot destroy/ destroy duplicate
« Reply #1 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

Marsh

  • Full Member
  • ***
  • Posts: 227
  • Comfort the disturbed, disturb the comfortable
Re: donot destroy/ destroy duplicate
« Reply #2 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 ();
}
}
}
« Last Edit: March 11, 2014, 09:10:40 AM by Marsh »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: donot destroy/ destroy duplicate
« Reply #3 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

Marsh

  • Full Member
  • ***
  • Posts: 227
  • Comfort the disturbed, disturb the comfortable
Re: donot destroy/ destroy duplicate
« Reply #4 on: March 11, 2014, 09:10:55 AM »
Fixed up the Tooltip and removed the Debug.Log I made this in a hurry.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: donot destroy/ destroy duplicate
« Reply #5 on: March 12, 2014, 04:44:56 AM »
Hi,

 thanks :)

bye,

Jean