playMaker

Author Topic: Playmaker tanking after spawning a few objects. [SOLVED]  (Read 1864 times)

MajorIdea

  • Full Member
  • ***
  • Posts: 131
Playmaker tanking after spawning a few objects. [SOLVED]
« on: April 12, 2017, 02:44:07 PM »
So essentially I have a game object that is meant to spawn clones of itself around itself, creating a sort of hex grid made out of game objects.

                               O O O
     O          ->          O O O
                               O O O



As to prevent overlapping clones the first state find the closest clone and checks for the distance. If its overlapping it despawns. If not it will spawn another and keep expanding.

To me, this logic seems rudimentary but sound. The problem is unity is completely tanking after the first iterations. What strikes me as peculiar is how drastic the framerate drops and looking at the profiler it seems to be coming from playmaker.



I've tried a bunch of things trying to debug it - using pool manager to instantiate instead of unity's create, deactivating the overlap prevention (i hear the find.gameobject by tag is slow), Spawning all adjacent clones in one single state instead of having a state for each one, even making a new scene with a bare bones game object and state machine. It always tanks.

Am I missing something or doing something incredibly dumb?
« Last Edit: April 13, 2017, 05:37:38 PM by MajorIdea »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Playmaker tanking after spawning a few objects.
« Reply #1 on: April 13, 2017, 02:33:35 AM »
Hi,

 Ok, first thing I would do is use an empty prefab with nothing, just an bare cube, and see if your spawning logic is good, maybe your logic spawns too many objects or goes in an infinite cycle.

then, when that works, you'll need to check your prefab and what it actually does when it starts, check each fsm and see what they do, turn them all off and turn them back on one at a time and check perfs, until you find the one giving problems and proceed further this way.

Yes, Find is not optimal, and could be the problem, in this case turn it on its head, have your fsm doing nothing ( or not this at least), and once you have spawned all instances, broadcast a global event where you pass the objects they need to store to work with, typically managers, the plyers etc, don't have each instance doing the same job, that's not optimal, do it in one place and have everyone else rely on this or be told about it in a passive way ( via a global event they implement),

Let me know how it goes :) If you can properly solve this problem, you'll gain a very important expertise on how to profile and solve these typical problems.

Bye,

 Jean

MajorIdea

  • Full Member
  • ***
  • Posts: 131
Re: Playmaker tanking after spawning a few objects.
« Reply #2 on: April 13, 2017, 05:37:16 PM »
This certainly has been an interesting exercise. I'm not sure I understand it but I managed to make it work following your suggestions.

It was an infinite cycle, but logically it should be ok as it was incremental. It didn't spawn infinitely all at once or even that quickly. But maybe unity doesn't like that sort of stuff.

Alternatively, it might have had something to do with the names. I was getting clones named like this:

Quote
Test Grow(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)

I changed the way they spawned by having them ask a manager to be spawned and the manager is the one actually doing the spawning. Changing that makes it run MUCH more smoothly and the names become something like this:

Quote
Test Grow(Clone)154

The find object by tag seems to not be the culprit as I noticed little diference with it on. Which is good because I need to use it a LOT.

So I guess that was it. It's not as smooth as I think it can be but its a stress test and a start. Thanks for the help! :)
« Last Edit: April 13, 2017, 05:40:09 PM by MajorIdea »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Playmaker tanking after spawning a few objects. [SOLVED]
« Reply #3 on: April 18, 2017, 02:41:49 AM »
Hi,

 yes, Unity do not like infinite loop, it's ok to do the same thing EVERY frame, but by Loop it generally means without waiting for the next frame, so this completly put the frame rate down, that's what PlayMaker has a detection system where you go over 100 loop it will warn you, but depending on how you have setup your fsm, it can't know...

Bye,

 Jean