AnnulusGames/LitMotion

Static variables must be explicitly initialized to work properly

Closed this issue · 3 comments

Thank you for your help.

When I Destroy or stop Unity playback in the middle of motion playback, the contents of the TaskPool seem to remain.

I have added the following code to LitMotionUniTaskExtensions.cs and it works fine, but could you please adopt it?

    internal sealed class MotionConfiguredSource : IUniTaskSource, ITaskPoolNode<MotionConfiguredSource>
    {
        static TaskPool<MotionConfiguredSource> pool;
        ...
        // Explicitly initialize the pool on Unity playback
        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
        static void Initialize()
        {
            pool = new TaskPool<MotionConfiguredSource>();
        }
        ...

I have also attached a zip file with a reproducible project. After unzipping and repeating the playback, the following error can be seen.
LitMotionTest.zip

MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.

Adding the code presented above will resolve the error. If you have any other suggestions, please let us know.

Oh, it's strange to see the Motion Tracker Window, it keeps remaining when playback ends during motion in the zip project.

I have replayed the project you gave us and cannot reproduce the issue; TaskPool initialization should not be necessary with or without Domain Reload.

The items not being removed from the MotionTrackerWindow is a known issue and will be fixed.

This issue is closed because I made a major implementation change in #113. If you encounter the issue again, please re-open it or create a new issue.