#How to get a GameObject return value out of an async void?

1 messages · Page 1 of 1 (latest)

grizzled oak
#

I've never really used async voids before but I want to try as I think it'll help optimize my ObjectPooler, I just can't figure this part out, how can I get a GameObject value out of this? If need be I can use a Coroutine but the same problem arises with those too.

unique patrol
#

Use explicit types instead of var to have an understanding of what types you're dealing with.

#

Also, to get the actual result from async methods you have to await them.

grizzled oak
unique patrol
#

You can call it normally in a non async method without awaiting it.

deep jetty
#

you should look into what the performance issue is before even going this route, especially if you dont understand async normally

#

i dont see why any of this would be async

halcyon basalt
#

please stop calling methods as "voids"

#

they aren't even void methods in this case

#

void means nothing is returned

grizzled oak
#

So I'm trying to split it up, with minimal delay between spawned objects.

deep jetty
#

look into why you're spawning a bunch of objects in the first place

halcyon basalt
#

bro what is it with beginners thinking "void" vs "method" is a pedantic distinction

#

calling it a void is literally just not even close to what it is

grizzled oak
grizzled oak
grizzled oak
grizzled oak
unique patrol
unique patrol
leaden kelp
#

probably a gc spike

unique patrol
#

Well, that's a completely different issue and should be solved differently.

#

That's why you should make sure you understand the issue correctly and provide the full context when asking for help.

leaden kelp
#

I dont understand it tho because the whole point of an object pool is to spawn everything at scene load

deep jetty
#

we are aware of the problem, we are reading the same text. we want to understand the actual issue and not just what they think will work
we dont just provide solutions if we know it wont be good in their case

grizzled oak
#

So okay, here's the part in the profiler, preferably I split this call over a couple of frames to maybe dampen the lag spike.

leaden kelp
grizzled oak
#

Just not the system I've used. Would it work here? As there could be any number of these objects.

leaden kelp
#

All youd have is ascript with an arry/list or w.e spawn everything at some random spot out of view of the play and then when you need them grab one from the pool

#

return it when youre done

#

the lag thats being caused spawning them will all happen at scene load and you wont get a lag spike when you grab a bunch of objects from the pool

grizzled oak
#

I see what you're saying but, wouldn't I still get a lag spike? I couldn't just predict the amount that I'd need and spawn that amount in on start.

#

(the objects I'm spawning are bullets and there could be any number of these)

leaden kelp
#

bullets have a really short life span

#

just start with a small pool size and slowly increase it till you stop getting exceptions the bullets eventually are no longer needed and returned to the pool

grizzled oak
#

(it's also a shotgun, so it spawns a bunch of them instantly...)

#

Idk, I don't think that kind of system will work for me.

leaden kelp
#

bro thats the industy standard for bullets

#

what you're trying to do is never going to work

grizzled oak
#

I could be wrong, but from what I see, there are too many variables and I'd rather it be done automatically.

unique patrol
#

Pooling IS automatic. It's not something you do manually by hand.

leaden kelp
unique patrol
#

Yes, you have to implement it obviously

leaden kelp
#

pooling stomething like bullets is not done automatic you have to program the shit

unique patrol
#

That's not what I meant at all.

leaden kelp
#

maybe im drunk my bad

unique patrol
grizzled oak
#

Yes, I'm aware and I use object pooling, all I need is some sort of queue system to prevent a ton of objects from being pooled in 1 frame and causing a big lag spike.

unique patrol
#

30 is no where near a ton of objects.

leaden kelp
grizzled oak
leaden kelp
#

so you use the bullets and put 30 of them back at once and it lags?

unique patrol
#

I think they're talking about the initial pool initialization

grizzled oak
leaden kelp
#

the inital pool initialization should happen at scene load

#

when are you currently initializing the pool?

#

when they take out the shotgun?

unique patrol
#

You usually want scene load frames to be in the frame budget as well. At least in a serious production project. Many platforms, like consoles wouldn't even let you publish, if you stall beyond some threshold.

cursive phoenix
#

and no, async void has nothing todo with perf, asyncs are never been about perf to begin with