Skip to content

Async Unitask methods do not works if called in a service constructor when the application starts #8

Description

@wendeljeske20

Framework Version
11.0.5

Unity Version
2022.3.30f1

Current Behavior
Calling a UniTask async method inside a service constructor do not works when the service is a pure class and has the "RequiredService" and "PreloadService" attributes.

Expected Behavior
Be able to run async methods called by the service construtor.

Steps to Reproduce
Create a interface that implements IService with RequiredService attribute
Create a pure class that implements the interface with PreloadService attribute
Declare a async method that awaits for any type of UniTask method
Call this method inside the service constructor

Basically, PlayerLoop is not initialized when calling the service constructor
I was able to implement this workaround to fix the problem:

        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
        public static void InitializePlayerLoop()
        {
            PlayerLoopSystem currentPlayerLoop = PlayerLoop.GetCurrentPlayerLoop();
            PlayerLoopHelper.Initialize(ref currentPlayerLoop);
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions