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.
#How to get a GameObject return value out of an async void?
1 messages · Page 1 of 1 (latest)
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.
Okay I can give this a go, but here's one of my other main issues with using these, how do I call an async void, without needing to call it from an async void? It always ends up as a snake where one void is async so they all have to be, am I missing something?
You can call it normally in a non async method without awaiting it.
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
please stop calling methods as "voids"
they aren't even void methods in this case
void means nothing is returned
Just seems that when I pool a bunch of objects in 1 frame it sends a lag spike.
So I'm trying to split it up, with minimal delay between spawned objects.
when you do a bunch of logic, a bunch of logic has to happen yes
look into why you're spawning a bunch of objects in the first place
use coroutines
You need to profile
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
Splitting it up between a delay, prevents a bunch of logic from being run at once. And I do know why I'm spawning a bunch of objects, it's deliberate and I'm trying to optimize spawning that many.
Same problems as in post title.
Already did and spawning all the objects at once causes the lag spike.
I'm not sure this will work, as I need to have out parameters, and async voids can't do that. Maybe I'll have to do something else?
Can you share the profiler data that made you come to this conclusion?
If you need output from an async method you have to await it. You should be able to do it from a normal method though.
I mean depending on what hes spawning his claim is pretty reasonable.
probably a gc spike
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.
this is what his problem hes trying to solve is
I dont understand it tho because the whole point of an object pool is to spawn everything at scene load
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
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.
why arent you just using an object pool that is initialized at scene load?
Just not the system I've used. Would it work here? As there could be any number of these objects.
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
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)
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
(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.
bro thats the industy standard for bullets
what you're trying to do is never going to work
I could be wrong, but from what I see, there are too many variables and I'd rather it be done automatically.
Pooling IS automatic. It's not something you do manually by hand.
are you drunk?
Unity Learn
Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.
Yes, you have to implement it obviously
pooling stomething like bullets is not done automatic you have to program the shit
That's not what I meant at all.
maybe im drunk my bad
@grizzled oak the people who created the engine advise you use object pooling for bullets
https://learn.unity.com/tutorial/introduction-to-object-pooling
Unity Learn
Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.
Anyways, async might be the next option after you have pooling.
But more importantly, what the hell do you have on your bullets that takes freaking 50ms to instantiate 30 of them.
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.
30 is no where near a ton of objects.
do you mean being put in or taken out of the pull ?
Put in.
so you use the bullets and put 30 of them back at once and it lags?
I think they're talking about the initial pool initialization
No, it's when they are first instantiated.
the inital pool initialization should happen at scene load
when are you currently initializing the pool?
when they take out the shotgun?
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.
object pooling with async void sounds like a disaster. You'd want to track those pooled objects properly meaning FireAndForget which what async void is all about will not be suitable in this case.
Async void generally be used only for event stuffs (button click etc).
Are you sure you want async void here?
and no, async void has nothing todo with perf, asyncs are never been about perf to begin with