Common Info
Hybrid Entities
Entities that combine DOTS entities and default GameObjects (game objects are tied by position to an entity).
How To Create
Create a prefab entity through the baking.
Add the
CopyTransformToGameObjectcomponent and add your custom init component to the baking process for initialization, pseudocode example:public struct InitComponentExample : IComponentData, IEnableableComponent { }
Spawn a prefab entity at runtime.
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
Create props prefab.
Add Props Authoring component.
Tick if necessary Has Custom Prop Reset.
Make sure that Props damage system support option is enabled.
Use a test scene to check that the props work.