playMaker

Author Topic: Change sorting layer on GameObject var w/PlayMaker?[SOLVED]  (Read 6087 times)

Bitterfish

  • Playmaker Newbie
  • *
  • Posts: 9
Change sorting layer on GameObject var w/PlayMaker?[SOLVED]
« on: April 02, 2014, 10:24:23 AM »
Hello,

I am trying to figure out the best & most efficient way to set/change a game object's sorting layer on the fly using PlayMaker.

Here is the scenario:

  • This is for a system of clickable powerups in an arcade-style, single-screen 2D game.
  • There are 4 types of powerups, chosen at random at a regular interval.
  • When the powerup is randomly selected, it is stored in a GameObject variable for later reference.
  • One of four valid screen locations is then selected, also at random.
  • Two locations are at the top of the screen, two are at the bottom.
  • In order to sort correctly with the other actors on screen, I need the objects at the top to be on one sorting layer and the objects at the bottom to be on another sorting layer.

The problem:
  • I want to change the sorting layer of the spawned powerup at the time it is spawned, based on its randomly selected spawn location.
  • I assumed I could do this using Set Property, and sure enough there is a Renderer/sortingLayerName property available if I drag a game object or prefab into the target field for that action.
  • However, if I try to use the gameobject variable I mentioned above, it does not work. When I flip the target field of the Set Property action over to variable, it only support Object variables, not GameObject.
  • So as far as I can tell, I can only change the sorting layer on a specific target gameobject or prefab, and not on a gameobject variable.

FWIW - The powerups are being spawned through PoolManager 5, but I could also simply spawn prefabs without any pool management & have the same issue.

I know I can make an FSM to do what I want here, just by using some redundant structures for each possible powerup and/or screen location. Or possibly by just making "Top" and "Bottom" variants of each powerup. I was hoping to keep it simple, efficient, and streamlined, though, so I am wondering if there's another option I am missing?

I hope this all makes sense. :)
« Last Edit: April 09, 2014, 07:55:27 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Change sorting layer on GameObject var w/PlayMaker?
« Reply #1 on: April 04, 2014, 07:37:12 AM »
Hi,

from a gameobject, you can get an object ( Sprite Renderer in our case).

 use "Get Component". if you have an Fsm Object set to type "SpriteRenderer", it will find it, and then you can use Set property to change the layer and order as you whish.

bye,

 Jean

Bitterfish

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Change sorting layer on GameObject var w/PlayMaker?
« Reply #2 on: April 09, 2014, 07:40:32 AM »
Thanks Jean!

velketor

  • Junior Playmaker
  • **
  • Posts: 69
  • Multimedia Marathon Man
    • Shawn Kilian Portfolio
Re: Change sorting layer on GameObject var w/PlayMaker?[SOLVED]
« Reply #3 on: June 24, 2018, 08:10:06 PM »
This doesn't work if you publish to WebGL.  Sprite Renderer never works.  Is there a way to Set Sorting Layer in PlayMaker without using Set Property?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Change sorting layer on GameObject var w/PlayMaker?[SOLVED]
« Reply #4 on: June 25, 2018, 07:04:27 AM »
Hi.
If you use Get/Set properties action you also need to use the Linker Wizard

There is a custom action on the Ecosystem called 'Set Sorting Renderer Layer'

Maybe that's what you are looking for?

velketor

  • Junior Playmaker
  • **
  • Posts: 69
  • Multimedia Marathon Man
    • Shawn Kilian Portfolio
Re: Change sorting layer on GameObject var w/PlayMaker?[SOLVED]
« Reply #5 on: January 06, 2019, 05:18:21 PM »
You are right!  I downloaded the code for this custom action SetSortingRendererLayer.cs here:

https://github.com/jeanfabre/PlayMakerCustomActions_U4/blob/master/Assets/PlayMaker%20Custom%20Actions/Renderer/SetSortingRendererLayer.cs

Then I pasted that code into a brand new C# script and placed it in my Playmaker actions folder.  I was able to use it as an Action in Playmaker and I can confirm it does work on WebGL for sorting layers.  You can even select objects that have no renderer, such as non-GUI text, and it will still assign it whatever sorting layer you tell it.  Pretty neat!  Thanks again =)