Common Info

Hybrid Entities

Entities that combine DOTS entities and default GameObjects (game objects are tied by position to an entity).

How To Create

  1. Create a prefab entity through the baking.

  2. Add the CopyTransformToGameObject component and add your custom init component to the baking process for initialization, pseudocode example:

    public struct InitComponentExample : IComponentData, IEnableableComponent
    {
    }
    
  3. Spawn a prefab entity at runtime.

  4. Create your own init system to initialize your hybrid entity, pseudocode example:

    [UpdateInGroup(typeof(InitializationSystemGroup))]
    public partial class InitSystemExample : SystemBase
    {
            private ExampleFactory exampleFactory;
            private EndInitializationEntityCommandBufferSystem entityCommandBufferSystem;
    
            protected override void OnCreate()
            {
                    base.OnCreate();
    
                    entityCommandBufferSystem = World.GetOrCreateSystemManaged<EndInitializationEntityCommandBufferSystem>();
            }
    
            protected override void OnUpdate()
            {
                    var commandBuffer = entityCommandBufferSystem.CreateCommandBuffer();
    
                    Entities
                    .WithoutBurst()
                    .WithStructuralChanges()
                    .WithAll<InitComponentExample>()
                    .ForEach((
                            Entity entity) =>
                    {
                            var exampleObject = exampleFactory.Get();
    
                            //Bind transform to entity
                            EntityManager.AddComponentObject(entity, exampleObject.transform);
    
                            //Add required component if missing
                            commandBuffer.AddComponent<CopyTransformToGameObject>(entity);
    
                            //Disable init component
                            commandBuffer.SetComponentEnabled<InitComponentExample>(entity, false);
    
                    }).Run();
    
                    entityCommandBufferSystem.AddJobHandleForProducer(Dependency);
            }
    
            //Some factory that is assigned from outside
    
            public void Initialize (ExampleFactory exampleFactory)
            {
                    this.exampleFactory = exampleFactory;
            }
    }
    

    Warning

    All code provided in the example is not part of DOTS City and is not intended for production.

Props

Props are active entities that react to damage.

How To Use

  1. Create props prefab.

  2. Add Props Authoring component.

  3. Tick if necessary Has Custom Prop Reset.

  4. Make sure that Props damage system support option is enabled.

  5. Use a test scene to check that the props work.

Props Authoring

_images/PropsAuthoring.png
Has custom prop reset : if checked, a custom reset system must be implemented for this object that contains PropsCustomResetTag component.

Custom reset of hydrant, example code:

Entities
.WithoutBurst()
.WithAll<PropsCustomResetTag>()
.WithAll<HydrantTag>()
.ForEach((
        Entity entity,
        ref PropsVFXData propsVFXData) =>
{
        if (propsVFXData.RelatedEntity != Entity.Null)
        {
                var particleSystem = EntityManager.GetComponentObject<ParticleSystem>(propsVFXData.RelatedEntity);
                particleSystem.Stop();
                particleSystem.gameObject.ReturnToPool();

                commandBuffer1.DestroyEntity(propsVFXData.RelatedEntity);
                propsVFXData.RelatedEntity = Entity.Null;
        }

        commandBuffer.SetComponentEnabled<PropsCustomResetTag>(entity, false);
        commandBuffer.SetComponentEnabled<PropsDamagedTag>(entity, false);

}).Run();