Transitioning to DOTS: Part 2 Proxy and Components

Disclaimer: This information presented uses Unity 2019.1.0f2 and Entities Preview Package 30-0.0.12. Since Unity is regularly adding to and depreciating the API, I cannot guarantee the methods I use will work beyond previous mention versions. If change to API break any parts of my code, please comment on it and I will try to address it as soon as possible. In addition, my intent is to use “Hybrid ECS”. It is also important to note, I will be using Hybrid ECS since a lot of Unity Built-In system are not support in Pure DOTS at this time.

The first step in creating in transition to DOTS, at least for me, is to develop the components.  Since this implement will use Hybrid ECS, GameObjects will have to be convert into Entities.  Currently, the Unity Entities package comes with a handle pre-written script to handle this. All that is required of the user to write the IComponentData Struct and Transfer Proxy script.

script 2

At this time, the focus is on recreating the Example Video from part on and will only have two influence map Proximity and Threat. Since I am using Hybrid ECS, We have to create a Proxy Mono Behavior using the IConverGameObjectToEntity interface. This allows a Monobehavior to be convert to entity at the Loading of Scene, when using the ConvertToEntity script. If you plan to use “Pure ECS” for your project, you will select convert and delete for the Conversion Mode. Also, note “Pure ECS” requires the use of Hybrid Renderer package.

test

Now that we have an entity, we have to access it and do something with it. For that, we need a ComponentSystem and a Job. Before start coding, let us think about how the influence system will work. An NPC will request to know the Influence at given location. In order to determine that it need to know all entities with an Influence Component in the scene. From there, the list of entities needs to be reduce to only the entities close enough to affect the influence of the sampling location.  With a condensed list of entity, the influence can be calculated and outputted.

This entry was posted in Dev Log, Development, Tutorials, Unity, WIP and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s