playMaker

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

Bitterfish

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Change sorting layer on GameObject var w/PlayMaker?[SOLVED]
« on: April 02, 2014, 07: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, 04:55:27 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 13535
  • Official Playmaker Support
    • View Profile
Re: Change sorting layer on GameObject var w/PlayMaker?
« Reply #1 on: April 04, 2014, 04: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
    • View Profile
Re: Change sorting layer on GameObject var w/PlayMaker?
« Reply #2 on: April 09, 2014, 04:40:32 AM »
Thanks Jean!

Shawn Kilian

  • Playmaker Newbie
  • *
  • Posts: 49
  • Multimedia Designer
    • View Profile
Re: Change sorting layer on GameObject var w/PlayMaker?[SOLVED]
« Reply #3 on: June 24, 2018, 05: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: 3613
    • View Profile
    • jinxtergames
Re: Change sorting layer on GameObject var w/PlayMaker?[SOLVED]
« Reply #4 on: June 25, 2018, 04: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?