playMaker

Author Topic: Send event to children causing garbage collection spikes  (Read 1152 times)

Mupp

  • Full Member
  • ***
  • Posts: 167
Send event to children causing garbage collection spikes
« on: January 24, 2021, 07:51:04 PM »
I have a system that spawns from a pool, a bunch of prefabs. On each of them I have a FSM template that makes them move after they have received an event. After a second or so, the first prefab is despawned and a new one is spawned, and so it continues.

Since I want to move the prefabs at a specific timing I use send event to gameobject/children, to the parent of the spawned prefabs. I do this every frame and there are about 25 objects at any time.

This causes extreme frame spikes every few seconds from garbage collection. I've checked in the logs that the event sends to the correct objects and they do. Also, if I disable the action, the spikes disappear.

Is this normal and what can I do about it? I must have a way to trigger the FSM's after other things has happened first.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Send event to children causing garbage collection spikes
« Reply #1 on: January 27, 2021, 07:54:07 AM »
hi.
What are the actions inside the children (after the event you send)
send event itself should not make spikes.

Creating multiple object at the same time can give spikes.
if that is the case you might want to look into pooling or create @ start of the scene and disable them. then enable when needed.

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: Send event to children causing garbage collection spikes
« Reply #2 on: January 27, 2021, 08:14:32 AM »
hi.
What are the actions inside the children (after the event you send)
send event itself should not make spikes.

Creating multiple object at the same time can give spikes.
if that is the case you might want to look into pooling or create @ start of the scene and disable them. then enable when needed.
Nothing special I think, just getting some FSM variables and calculation of a new position that is set by a 3rd party action to a spline.

Like I said I already use a pool. I did a deep profiling and it says it's the send event action that are causing the spikes.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Send event to children causing garbage collection spikes
« Reply #3 on: January 27, 2021, 03:15:11 PM »
Are you profiling in the editor or with a build? Some Unity commands create garbage in the editor but not in a build, so it's important to profile builds. Either way, I'll look into the cause of this in the editor, but I'm curious if you're seeing the same thing in a build.

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: Send event to children causing garbage collection spikes
« Reply #4 on: January 27, 2021, 06:03:16 PM »
Are you profiling in the editor or with a build? Some Unity commands create garbage in the editor but not in a build, so it's important to profile builds. Either way, I'll look into the cause of this in the editor, but I'm curious if you're seeing the same thing in a build.
I've tested it in build. Now I'm not skilled enough to say what exactly happens, but there is garbage collection happening from Playmaker. I don't know what's causing it and it's way less severe. From about 30-40 ms in editor to about 7 in build. It also happens less frequent.

Maybe this is normal or not, I can't tell.