pancake-llc / foundation

Game Mobile Foundation (Android + iOS) Using Unity3D. Simple, Fast and no GC
MIT License
111 stars 16 forks source link

Sir, do you know about new `Object.InstantiateAsync` in unity 6 #141

Closed IAFahim closed 3 weeks ago

IAFahim commented 3 weeks ago

I just found out from here: https://github.com/keijiro/InstantiateAsyncTest?tab=readme-ov-file

Prewarm for pooling can become really powerful.

aprius commented 3 weeks ago

Yeah it's a great API, I tested it a while back, it's a testament to the async era. You can now use it as an optimization technique for generating heavy objects without having to worry too much about when they're generated like dynamically loading maps...

aprius commented 3 weeks ago

Yaa, using it in prewarm pool will be really effective and of course it also comes with RequestAsync

IAFahim commented 3 weeks ago

Of course you had checked it before 🥲 and I thought I have a new information. But I don't understand how you could have known about it because its only available on unity 6.1

https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Object.InstantiateAsync.html

And about RequestAsync it's there on the documents on unity site(I might not know how to look that good)

aprius commented 3 weeks ago

No, It was added since unity 2022.3.20

IAFahim commented 3 weeks ago

Ehh bad unity website documentation design.

Screenshot_2024-11-04-14-56-11-813_org mozilla firefox~2

Thank you Sir for your guidance. You always know a lot, and helpful.

aprius commented 3 weeks ago

I just tried brenchmarking between Instantiate and InstantiateAsync but maybe this visual explanation is too obvious here. And there is no problem if calling Request or Return while PrewarmAsync is not completed

aprius commented 3 weeks ago
    public GameObject prefab;

    private void Start()
    {
        prefab.PrewarmAsync(10, 10).Forget();
    }
IAFahim commented 3 weeks ago

Thank you for explanation, Sir.

    public GameObject prefab;

    private void Start()
    {
        prefab.PrewarmAsync(10, 10).Forget();
    }

Isn't the second parameters in PrewarmAsync a CancellationToken in this repo. Are a you trying out a new method?

aprius commented 3 weeks ago

The prewarm method previously available for IAsyncObjectPool with the existing async implementations will be no different, the new Prewarm method added for SharedGameObjectPool and GameObjectPool which implements the utility APIs for GameObject

aprius commented 3 weeks ago

Maybe I'll add CancellationToken to it too