ECS for production

Hello

I’m looking for information about ECS for prod.

We are really interested by the whole DOTS stack, and were wondering if it was wise to go in real production yet.
We basically are developing quite a big game, and are most of all interested by the “SubScene” workflow and feature.
I’ve already managed to make it work on a prototype but we have some difficulties outside of the “streaming chunks of static meshes” consideration. Streaming scenes work and it is incredibly fast, but we encounter difficulties to (non exhaustive list) :

  • render animated skinned meshes
  • click on collider
  • have basic OnTrigger methods detect anything

To sum-up, we have difficulties to mix Subscene and “classic” stuff, and couldn’t find really usefull documentation.

I know that going full ECS won’t be a solution for now, but I wanted to know if it is viable to go hybrid at the moment.

And if so, I’d like to know what’s the status about these topics / how to integrate them in an ECS context :

  • AssetBundles
  • Basic Physics (raycasts / triggers)
  • Is it working on mobile (I guess cause megacity is) and consoles ?

We could be happy with “just” Subscenes, skinned mesh animations and basic physics…

Any help appreciated.

You can see my pinned thread on forum. We’re using it for production.
5118182--505400--upload_2019-10-29_16-51-1.png

Why not? Just write your own stuff which not ready (yet) from unity :slight_smile:

DOTS will be coming out of beta and will be production ready by the end of this year I believe. And I would say it’s pretty safe to use it for production right now. I have been using for over a year now, and didn’t experience much churn with api changes over the past year. And with the new ConvertToEntity workflow, it makes it really easy and very viable to do a hybrid approach. And yes, it works for mobiles and consoles. And there is plenty of physics support for DOTS.

Physics and queries are in a good state as long as you don’t need to mutate colliders at runtime other than swapping collider assets.

An official DOTS animation package will be coming out soon. However, you’ll want to keep this project handy as it solves a few use cases I don’t think the animation package will solve: GitHub - joeante/Unity.GPUAnimation: Simple but very fast GPU vertex shader based animation system for Unity.Entities

In Unity.Physics, there’s a custom job type for reacting to triggers. And you can fire off raycasts from within a job.

Can’t comment much on Asset Bundles. Those might be partially replaced in the new build pipeline.

I don’t think Switch has Burst support yet.

I think it’s ready for production in 2020 even though a lot of thing still not be confirmed (they’re listed as 2019.3/2020.1 experimental) such as LiveLink, DOTS Animation, DOTS Audio, etc. You can check from Unite Copehagen roadmap.

2 Likes

Bit offtopic, but is this workflow released?

Parts of it, but not all of it like the auto-generated authoring time behaviors.

1 Like

Thanks for your feedbacks.
My starting point is having scripts on objects inside a sub scene but si far I didn’t manage to make them work.
I’m trying to simply log something.

What am I doing wrong ?

using Unity.Entities;

public struct NpcSimpleAnimationData : IComponentData
{
}
using Unity.Entities;
using UnityEngine;

public class NpcBridge : MonoBehaviour, IConvertGameObjectToEntity
{
    [SerializeField]
    NpcSimpleAnimationData Data;

    public void Convert(Unity.Entities.Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        Debug.Log("Try to convert..."); //this is executing when pressing "edit" button on the subscene
        dstManager.AddComponentData(entity, Data);
    }
}
using Unity.Entities;
using UnityEngine;

public class NpcSimpleAnimationSystem : ComponentSystem
{

    private EntityQuery _npcGroup;

    protected override void OnCreateManager()
    {
        _npcGroup = GetEntityQuery(typeof(NpcBridge));
        Debug.Log(_npcGroup.CalculateLength());
    }

    protected override void OnUpdate()
    {
        var entities = _npcGroup.ToEntityArray(Unity.Collections.Allocator.Persistent);
        var animators = _npcGroup.ToComponentArray<Animator>();
        if(entities.Length > 0)
        {
            for(int i = 0; i < entities.Length; i++)
            {
                Debug.Log(animators[i]);
            }
        }
    }
}

@Max_Lag When inside a sub-scene the conversion systems run once when you save the sub-scene and the result is saved in the asset created.

Also you are adding a component of type NpcSimpleAnimationData to the entity, but your ComponentSystem is not querying for that anywhere? Your system is instead looking for NpcBridge.

You’re right, my bad :slight_smile:
But I still get nothing when asking :

    protected override void OnCreateManager()
    {
        _npcGroup = GetEntityQuery(typeof(NpcSimpleAnimationData), typeof(Animator));
        Debug.Log(_npcGroup.CalculateLength());
    }

You adding Animator by AddComponentObject anywhere? If not, your system never runs cause entity with this archetype just not exist

Updated code below, but still nothing :frowning: Sorry guys

It goes in OnCreateManager but prints 0 length on _npcGroup and never prints in OnUpdate

Any idea ?

And now I have annoying warnings :

using Unity.Entities;
using UnityEngine;

public class NpcBridge : MonoBehaviour, IConvertGameObjectToEntity
{
    [SerializeField]
    NpcSimpleAnimationData Data;

    public void Convert(Unity.Entities.Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        Debug.Log("Try to convert... ");
        dstManager.AddComponentData(entity, Data);
        dstManager.AddComponentObject(entity, gameObject.GetComponent<Animator>());
    }
}
using Unity.Entities;
using UnityEngine;

public class NpcSimpleAnimationSystem : ComponentSystem
{

    private EntityQuery _npcGroup;

    protected override void OnCreateManager()
    {
        _npcGroup = GetEntityQuery(typeof(NpcSimpleAnimationData), typeof(Animator));
        Debug.Log(_npcGroup.CalculateLength());
    }

    protected override void OnUpdate()
    {
        var entities = _npcGroup.ToEntityArray(Unity.Collections.Allocator.TempJob);

        Debug.Log(entities.Length);
      
        var animators = _npcGroup.ToComponentArray<Animator>();
        if(animators.Length > 0)
        {
            for(int i = 0; i < animators.Length; i++)
            {
                Debug.Log(animators[i]);
            }
        }

        entities.Dispose();
    }
}

Isn’t Animator an old non-component class? I admit I haven’t used AddComponentObject, but can imagine the gameobjects only existing (temporarily) in the conversion world.

At least it’s not an ECS component so I doubt the query will work with it.

Try a round of eliminations? For example if you remove Animator from the query, do you then get your system to run?

P.S. If you aren’t aware then there is a brand new DOTS-based Animation system coming as a preview package very soon (a few weeks according to last info we saw).

Awesome, this is really the only must-have I need, to go forward in my prototype.
I can imagine workarounds for almost everything else but this might save me a lot of my time :slight_smile:

I’ll wait for this package then, thanks ofr the answers.

To be honest I was trying to do as this guy did :

But with the SubScene black box context I guess it’s a bit more complex

Oh you’re using subscenes, yeah all GO in the end will be destroyed when subscene will be converted, and your Animator wouldn’t exists anymore. Moreover when you’ll try to add some component object to entity whle conversion (in GameObjectConversionSystem or through IConvertGameObjectToEntity) and rebuild entity cache or save this subscene data it should throw you error “Serialization of GameObject components is not supported for pure entity scenes”

For this case you should use conversion workflow without subscenes.

Isn’t OnCreateManager deprecated?

Renamed to OnCreate, same as OnDestroyManager => OnDestroy