Oshigawa
Full Member
 
Posts: 228
Posts: 228
|
Post by Oshigawa on Jan 4, 2022 5:25:46 GMT
Hi,
i'm porting the game to PS4 and loading times are really bad due to sheer amount of items pooled, i expect it to be even worse on Switch. It's completely blocking the main thread. Any way to fill the pools in a non-main thread?
I don't know if making (for example) four minipoolbosses and instantiating them on separate threads will speed things up a bit? Though i suppose that will only instantiate them on the other thread, filling the pools will be done on the main thread anyway... Sorry if the questions are dumb, i'm new to multithreading and it's too late for some more radical improvements.
|
|
Oshigawa
Full Member
 
Posts: 228
Posts: 228
|
Post by Oshigawa on Jan 4, 2022 15:17:51 GMT
Oh yes, another dumb question. I raised initialization frames to say 10000 in minipoolboss. Will i be able to use the created items until the initialization is not completely complete?
|
|
|
Post by DarkTonic Dev on Jan 4, 2022 16:14:05 GMT
2nd question, nope. But if they're already in the Scene you can use them.
I don't know anything about multithreading and Unity, including whether that's even a thing? Do you have any links?
But yes, that's what typically happens (blocks the thread).
-Brian
|
|
Oshigawa
Full Member
 
Posts: 228
Posts: 228
|
Post by Oshigawa on Jan 5, 2022 23:29:30 GMT
It's complicated and it would require a lot of rehauling, plus Unity is not really thread safe unless you use the job system and so on... Anyway, i have a miniboss pool with around 900 objects which i'm conveniently initializing over the course of 4200 frames (70 seconds), which should amount to one object every five frames. However, poolbossmini is creating the items in batches and causing spikes.  All of the three spikes you see are minipoolboss creating 40-70 items at once, doing nothing for ~100 frames, then doing it again.
|
|
|
Post by DarkTonic Dev on Jan 6, 2022 0:17:58 GMT
Why would it be doing nothing for 100 frames? What do you have your Initialization Frames set to in Pool Mini Boss?
|
|
Oshigawa
Full Member
 
Posts: 228
Posts: 228
|
Post by Oshigawa on Jan 6, 2022 8:02:11 GMT
To 4200 (i've changed the script).  It instantiates a group of items causing a huge spike in GC, then it does nothing, then it instantiates another group of items with a spike, then idles, then again. First spike is the Artillery strike bullet, second spike is ArtilleryStrikeSkull, third spike is BigBullet and so on. As you can seei in the profiler, all 40 BigBullet items are created in a single frame. That's not how i was hoping that this would work and i suppose it shouldn't.
|
|
Oshigawa
Full Member
 
Posts: 228
Posts: 228
|
Post by Oshigawa on Jan 6, 2022 8:13:46 GMT
Same thing happens when using the regular pool boss too, it initializes every frame (no items are appearing in the hierarchy during the init process) and then BAM, all 5000 prefabs get dumped in the scene at once when the init is complete.  Shouldn't the point be that the items are instantiated during those 1000 frames (5 items per frame) so i can use free cpu time to load the items i need until the moment i need them from the pool?
|
|
|
Post by DarkTonic Dev on Jan 6, 2022 16:16:24 GMT
Yes, and that is what is happening in the code. As for why they don't appear in the Hierarchy, I'm not sure.
I am also not clear on your last question. Please rephrase it.
|
|
Oshigawa
Full Member
 
Posts: 228
Posts: 228
|
Post by Oshigawa on Jan 6, 2022 17:04:19 GMT
They are not appearing in the hierarchy because they are not created, nor the instantiations appear in the profiler.
If i have 5000 items that i want to create during the course of 1000 frames, 5 items should appear in the hierarchy every frame (i haven't thoroughly read the code, but i presume it should work that way). That does not happen, all that happens is that the entire category is spawned in a single frame.
I didn't measure (but i will make a test), but it seems to me that if i have 1000 items in 10 categories set to spawn over 1000 frames, each category will spawn in one frame every 100 frames.
Btw i'm calling CreateItems() to start the spawning.
I also tried to turn on auto create without calling CreateItems(), but the same thing happens.
|
|
|
Post by DarkTonic Dev on Jan 6, 2022 17:25:42 GMT
Correct, it will create an equal fraction of the pool items every frame. I have observed it to work, although I didn't check out the Hierarchy during the process.
It doesn't care about categories. If you have 10 items for 5 frames, it will Instantiate all the clones of each of 2 items every frame.
|
|
Oshigawa
Full Member
 
Posts: 228
Posts: 228
|
Post by Oshigawa on Jan 6, 2022 18:18:30 GMT
Correct, it will create an equal fraction of the pool items every frame. I have observed it to work, although I didn't check out the Hierarchy during the process. It doesn't care about categories. If you have 10 items for 5 frames, it will Instantiate all the clones of each of 2 items every frame. Sorry, i did not mean categories, i meant items. Item #1 is spawned in defined quantity in one frame, then nothing happens for a while, then item #2 is spawned in defined quantity in one frame and so on...as usual, i'll try it in an empty project, but this is not working as intended on my end.
|
|
|
Post by DarkTonic Dev on Jan 6, 2022 18:28:55 GMT
Ok, try it in an Example Scene.
|
|
Oshigawa
Full Member
 
Posts: 228
Posts: 228
|
Post by Oshigawa on Jan 7, 2022 15:23:42 GMT
I reproduced it and sent the link for the project to your e-mail, unity 2019.4.29f1, CGK latest version downloaded from the store. Pool Boss Mini is set to 100 initialization frames with 5000 objects.
PoolBoss.Update() and PoolMiniBoss.Update() is being called every frame, but nothing is appearing in the hierarchy. GC Alloc for both processes is zero, time is zero, the calls don't do anything.
You have a frame counter in the upper left corner, when it hits 100, all 5000 prefabs will be instantiated at the same time causing a spike. Sorry, it is definitely NOT working as intended 
|
|
|
Post by DarkTonic Dev on Jan 7, 2022 16:59:09 GMT
Maybe I wasn't clear. The example you sent is behaving correctly. It cannot Instantiate a fraction of one Pool Item, including all its clones, in a frame. One Pool Item means the prefab itself and however many clones. It doesn't care how many clones you have specified (5000 in your case), they will all be created in a single frame.
So if you wanted it to take 100 frames and space it out, you'd need 100 different prefabs set up there in order to see some each frame.
-B
|
|
|
Post by DarkTonic Dev on Jan 7, 2022 17:00:03 GMT
I can make the slider so that it doesn't allow you to exceed the number of Pool Items, that used to work. Would that help?
|
|