neuecc / UniRx

Reactive Extensions for Unity
MIT License
7.09k stars 890 forks source link

UniRx currently breaks update loop in Unity ECS (Systems) #401

Open LamPham opened 5 years ago

LamPham commented 5 years ago

I've been working on an ECS (Entity Component System) setup for my game and integrating UniRx immediately prevents OnUpdate for all Systems.

I am not quite sure what could cause this but it may involve the experimental PlayerLoopSystem clashing with ECS.

Testing on: Unity 2019.1.0f2 Packages: Entities: preview.30 - 0.0.0.12 Hybrid Renderer: preview.10 - 0.0.1

We can quickly reproduce this with Unity's Sample ECS project. Unity ECS Samples

  1. First run any sample (we tested with "HelloCube_01_ForEach") without UniRx and access the Entities Debugger (Window > Analysis > Entity Debugger) and notice that the world is displayed with active Systems and their execution times.

  2. Add in UniRx to the project. It will deactivate all Systems (everything is grayed out) when played.

Thank you in advance,

johnathandinh commented 5 years ago

Workaround below, have to translate the text.

https://notargs.hateblo.jp/entry/ecs_unirx

Just init this bootstrap script before your ECS scripts.

using UnityEngine;
using Unity.Entities;

public class Bootstrap : MonoBehaviour
{
    void Start()
    {
        var playerLoop = ScriptBehaviourUpdateOrder.CurrentPlayerLoop;
        UniRx.Async.PlayerLoopHelper.Initialize(ref playerLoop);
    }
}
ryanhorath commented 3 years ago

ScriptBehaviourUpdateOrder.CurrentPlayerLoop has been removed from the API. Is there still a way to do this properly?