playMaker

Author Topic: Adding Bounds Support  (Read 2136 times)

blackant

  • Hero Member
  • *****
  • Posts: 521
  • http://blackantmaster.com
    • blackantmaster.com
Adding Bounds Support
« on: December 31, 2018, 02:25:25 PM »
Hello,

happy new year by the way !!!! ;)

i'm surprised because on the forum there is 0 result on Bounds search...
and i'm writing here because the playmaker actions doesn't containt any way to use them in the editor.
and i was writing a code specially for it:

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Adding Bounds Support
« Reply #1 on: January 21, 2019, 12:31:26 AM »
Hi,

 can you show the code of the custom action. Bound is supported, I made plenty of actions using bound one way or the other.

check out GetColliderBounds from the Ecosystem for example.

 Bye,

 Jean

blackant

  • Hero Member
  • *****
  • Posts: 521
  • http://blackantmaster.com
    • blackantmaster.com
Re: Adding Bounds Support
« Reply #2 on: January 21, 2019, 01:40:24 AM »
There is nothing special in my code, i certainly missed something.
yes i ste it as public, this is why i get the message

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{

[ActionCategory("Terrain")]
[Tooltip("Get the local bounding box of the TerrainData object.")]
public class GetTerrainBounds : FsmStateAction
{
public Terrain terrain;

public Bounds bounds;

// Code that runs on entering the state.
public override void OnEnter()
{
bounds = terrain.terrainData.bounds;
Finish();
}


}

}
« Last Edit: January 21, 2019, 01:43:30 AM by blackant »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Adding Bounds Support
« Reply #3 on: January 21, 2019, 03:58:23 AM »
Hi,

 yes, Bounds is a struct, you can't use it like that, you need to save it as a private variable and expose its properties individually.

Typically I solved this kind of problem with a public static dictionnary where the key is a custom string acting as a reference that you set in your action ( like arrayMaker or xmlMaker), and then other actions can use bounds by this reference key. This is the best option as far as I can see. Otherwise you need to create serializable class which create garbage collection and it's not that great...

Code: [Select]
using UnityEngine;
using System.Collections.Generic;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("Terrain")]
    [Tooltip("Get the local bounding box of the TerrainData object.")]
    public class GetTerrainBounds : FsmStateAction
    {
        // you can then get to a bound using: GetTerrainBounds.BoundsLUT["My Reference"];
        public static Dictionary<string, Bounds> BoundsLUT;

        public Terrain terrain;

        public FsmString BoundReference;

        // Code that runs on entering the state.
        public override void OnEnter()
        {
           
            if (BoundsLUT == null)
            {
                BoundsLUT = new Dictionary<string, Bounds>();
            }

            BoundsLUT[BoundReference.Value] = terrain.terrainData.bounds;

            Finish();
        }
    }
}


one last option is to create scriptableObject again as a wrapp of your bound, but again you need to create them carefully and at edit time, so that they don't crate garbage collection and/or memory leak.

Bye,

Jean