playMaker

Author Topic: Spreading out heavy actions with Next Frame Event  (Read 2420 times)

joepalos

  • Playmaker Newbie
  • *
  • Posts: 28
    • View Profile
Spreading out heavy actions with Next Frame Event
« on: August 12, 2016, 12:51:37 PM »
Hello,

This is more of a "performance design" question.

I'm wondering if this could work:

At certain points in my game, I create many prefab copies at once (using Unity's Instantiate() via the Create Object action).

However, being that Unity's Instantiate() is pretty damn slow because of awful Garbage Collection routines, I get stutters. Instantiating many objects at once can drop the framerate very low for a couple frames, and it's noticeable.

So my question is: using Next Frame Event, could I "spread out" the creation (instantiation) of these GameObjects over several frames? Or would it be more appropriate to use the Wait action, with a value of 0.0166 seconds? (the time it takes to generate 1 frame at 60 frames per second, 1/60 = 0.0166)

note: I know about object pooling. It wouldn't work on my game system.
« Last Edit: August 12, 2016, 12:53:48 PM by joepalos »

kavery

  • Full Member
  • ***
  • Posts: 113
    • View Profile
Re: Spreading out heavy actions with Next Frame Event
« Reply #1 on: August 12, 2016, 01:11:09 PM »
In my tests a wait works for that.. certainly way better than a bunch at once. You might want to wait 2 or 3 frames in between but I could be wrong on that.

joepalos

  • Playmaker Newbie
  • *
  • Posts: 28
    • View Profile
Re: Spreading out heavy actions with Next Frame Event
« Reply #2 on: August 12, 2016, 01:24:36 PM »
I'm trying to avoid waiting more than 1 frame to make it the least noticeable. Realistically, nobody's gonna notice 1 frame more or less at 60 per second, but I'd like to make it optimum.

I'm thinking the Wait action solution has the problem of not taking into account the time already spent in the current frame in other tasks. As in, it may start counting time after 1ms or something instead of immediately.

Time.deltaTime might not work either, since it's time data from the LAST frame...I wish there was a reliable way to count the time passed since the current frame started getting built.

Zeldag

  • Full Member
  • ***
  • Posts: 198
    • View Profile
Re: Spreading out heavy actions with Next Frame Event
« Reply #3 on: August 12, 2016, 01:35:58 PM »
Hi,

Maybe you could use 2 'next frame events'?


joepalos

  • Playmaker Newbie
  • *
  • Posts: 28
    • View Profile
Re: Spreading out heavy actions with Next Frame Event
« Reply #4 on: August 12, 2016, 01:56:53 PM »
That would make the process take 2 times as long, as it would be spread out over 2 times as many frames.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4451
    • View Profile
    • jinxtergames
Re: Spreading out heavy actions with Next Frame Event
« Reply #5 on: August 12, 2016, 03:12:57 PM »
Hi,
There is a custom action called "next frame event advance" on the Ecosystem
It has the option to set how many frames, so you can play around with it to get the best solution.

Still pooling would be the best option.
So i will ask why this would not work on your game system?
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

kavery

  • Full Member
  • ***
  • Posts: 113
    • View Profile
Re: Spreading out heavy actions with Next Frame Event
« Reply #6 on: August 12, 2016, 09:19:15 PM »
If you can't pool for some reason, maybe you can create all at run start and keep them turned off - then activate when you need em. You can have hundreds of gameobjects inactive w/out much overhead if any.

You could also have these already prepared in a scene.


joepalos

  • Playmaker Newbie
  • *
  • Posts: 28
    • View Profile
Re: Spreading out heavy actions with Next Frame Event
« Reply #7 on: August 13, 2016, 01:25:20 AM »
Still pooling would be the best option.
So i will ask why this would not work on your game system?
It's complicated to explain, but the short version is that there are (potentially) thousands of slightly different, memory-light objects, and they are different in a way that is not modifiable or settable at runtime.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4451
    • View Profile
    • jinxtergames
Re: Spreading out heavy actions with Next Frame Event
« Reply #8 on: August 13, 2016, 02:55:52 AM »
Hi,
Then i still think pooling or pre-loading them would be your best option.
to create 1000+ prefabs will be close to impossible without lag.
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

joepalos

  • Playmaker Newbie
  • *
  • Posts: 28
    • View Profile
Re: Spreading out heavy actions with Next Frame Event
« Reply #9 on: August 13, 2016, 05:46:54 AM »
I am aware of this. The point of this thread is to learn the proper way to spread their creation over enough frames so that the lag is not noticeable by the player.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4451
    • View Profile
    • jinxtergames
Re: Spreading out heavy actions with Next Frame Event
« Reply #10 on: August 13, 2016, 01:43:55 PM »
Hi,
Can you show a video of what you are doing?
Maybe there is a different solution for it (using arrays or something different)

I don't think that there is a proper way for creating 1000+ prefabs, even in a few frames.
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions