playMaker

Author Topic: PlayMaker causing Android game to run slow[SOLVED]  (Read 4642 times)

velketor

  • Junior Playmaker
  • **
  • Posts: 69
  • Multimedia Marathon Man
    • Shawn Kilian Portfolio
PlayMaker causing Android game to run slow[SOLVED]
« on: August 05, 2019, 03:13:06 PM »
Hello,

I have a game I've made that runs smooth as butter on WebGL and Windows PC, but if you port it to Android it runs at 60fps until my first enemy spawns, then it drops by about 10fps per enemy.  I found the issue to be PlayMaker. 

When I disable the PlayMaker component on my spawned prefab enemy, the game stays at 60fps, but the moment I enable the PlayMaker component on that prefab, the game drops by about 10fps.  Since I have 20 enemies, the framerate drops to nearly 5fps by the time they are all spawned.

As a test, I removed the PlayMaker component from my prefab enemy and ran the game.  The game stays at 60fps.  Then I added an empty PlayMaker component and ran the game, the framerate drops to 10fps again. 

What exactly is going on here?  Why does PlayMaker not want to play nice on Android?  In my test, there is not a single action on the PlayMaker component, so I don't see how it can be affecting performance.

Please advise!
« Last Edit: August 08, 2019, 01:53:53 AM by jeanfabre »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: PlayMaker causing Android game to run slow
« Reply #1 on: August 05, 2019, 04:19:12 PM »
Strange! What versions of Playmaker and Unity?
Are there any log errors in logcat?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PlayMaker causing Android game to run slow
« Reply #2 on: August 06, 2019, 01:54:46 AM »
Hi,

 my gut feeling is that it's not PlayMaker that is the problem but what you do in this fsm(s), for example if you try to find a gameobject by name this is slow for example, and on low end devices this can make a huge difference. my experience with IOS and Android is that Android always under perform, so if your game is running smooth on IOS, it might not on Android.

 the only way to be sure is to profile, even in editor and see inside your prefab what takes the most time, you can profile all the way to each actions, chances are that the same pattern will occur on android but with even more penalty.

What is this fsm doing exactly? do you have only one?

Bye,

 Jean

velketor

  • Junior Playmaker
  • **
  • Posts: 69
  • Multimedia Marathon Man
    • Shawn Kilian Portfolio
Re: PlayMaker causing Android game to run slow
« Reply #3 on: August 06, 2019, 11:40:31 AM »
Thank you for the response.  Unity Version 2018.2.10f and PlayMaker Version 1.9.0.p4.  The FSM on each of my spawned enemy prefabs has many states with many actions, but here is the initial default state each enemy prefab starts in:


This runs great on WebGL and PC.  Android doesn't like it though.
« Last Edit: August 06, 2019, 11:43:41 AM by Shawn Kilian »

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: PlayMaker causing Android game to run slow
« Reply #4 on: August 06, 2019, 01:20:10 PM »
That's a lot of 'set properties'.
Perhaps there's an issue hidden in the building parameters that collides with something related to Playmaker.

velketor

  • Junior Playmaker
  • **
  • Posts: 69
  • Multimedia Marathon Man
    • Shawn Kilian Portfolio
Re: PlayMaker causing Android game to run slow
« Reply #5 on: August 07, 2019, 07:15:33 AM »
That's the thing though.  I've disabled every action in this FSM, one by one, and republished to my phone and it doesn't fix the issue.  My guess is that you cannot have an FSM with 20+ actions in it on mobile or it will simply lag, even if the FSM in question is not even being used.  Maybe PlayMaker has a limitation on the amount of actions that can safely be inside an FSM on Android.

For instance, this FSM has about 20 states, each state has about 20 actions.  Even though the enemies only sit in 1 state at a time, I think the FSM just might contain too much information for Android to handle.

If using "Set Properties" has a limitation, I wonder what it is and why it only affects Android.  I haven't tested on iPhone yet because I don't have a MAC.

velketor

  • Junior Playmaker
  • **
  • Posts: 69
  • Multimedia Marathon Man
    • Shawn Kilian Portfolio
Re: PlayMaker causing Android game to run slow
« Reply #6 on: August 07, 2019, 08:22:23 AM »
I ran the profiler and found that the "garbage collection" feature of Unity is causing the spikes everytime I spawn a new enemy. 



Unfortunately the fix for this was only released in Unity 19.1a10: Incremental Garbage Collection.  It splits up the garbage collection into incremental chunks instead of all at once.  The full article is here if you want to read more about it: https://blogs.unity3d.com/2018/11/26/feature-preview-incremental-garbage-collection/

I cannot update my Unity version to 2019 because it breaks a ton of other parts of my game (already tried) so for now the Android version of my game will be laggy =(

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: PlayMaker causing Android game to run slow
« Reply #7 on: August 07, 2019, 10:23:56 AM »
Hi.
I think you need to find out why you have large garbage.

Usually destroying creates a lot of garbage.

Are you Creating/destroying @runtime?

If those are the same prefab, you might want to pool instead.

velketor

  • Junior Playmaker
  • **
  • Posts: 69
  • Multimedia Marathon Man
    • Shawn Kilian Portfolio
Re: PlayMaker causing Android game to run slow
« Reply #8 on: August 07, 2019, 11:32:56 AM »
I figured it out!  The Profiler was able to point me to a script unrelated to PlayMaker.  I removed that script and the game is running buttery smooth now.

I'm guessing that PlayMaker and this other script were having a conflict, so removing either of them fixed the issue.  Thank you for everyone's help and support.

Bottom line, use the Profiler to pinpoint the issue and you'll find what the culprit is.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PlayMaker causing Android game to run slow
« Reply #9 on: August 08, 2019, 01:53:41 AM »
Hi,

 very good!, Iam glad you sorted this out.

 Indeed, the number of actions per state doesn't impact perfs, a PlayMaker action is a regular script like any other class on other systems, so when you have perfs issues like that, it's usually what the action or the script does with Unity, and not itself by just being there.

What was the other script about?

Bye,

 Jean