Hi, I am new in DOTS and most probably doing something stupid but I cant find the Convert To Entity script in unity.
I have added these packages:
burst
collections
core RP Library
custom NUnit
Entities
Entities Graphics
Mathematics
Mono Cecil
Scriptable Build Pipeline
Searcher
Serialization
Shader Graph
Test Framework
TextMeshPro
Timeline
Unity Physics
Unity Profiling Core API
Unity UI
Universal RP
Version Control
Visual Scripting
Ok so if anyone else is facing this problem then this is because you are following old tutorials.
to convert gameobjects to entities you just have to put them in a sub scene.
This is because conversion workflow is obsolete since entities 1.0
and became replaced by new baking workflow.
Entity “baking” workflow is different from previous conversion workflow, so give yourself some time to understand it and accommodate.
The most important difference: there is no runtime conversion anymore. GameObject
→ Entity
conversion is still here but it must happen at build-time in Editor (long before game starts) and uses different components & API. IConvertGameObjectToEntity interface became replaced by Baker class, which looks something like this:
using UnityEngine;
using Unity.Entities;
[DisallowMultipleComponent]
public class CupOfCoffeeAuthoring : MonoBehaviour
{
[Range(0,1)] public float Fill = 0.5f;
[Min(0)] public int Intensity = 5;
public GameObject InstantiateOnDestroyed;
public class Baker : Baker<CupOfCoffeeAuthoring>// <<< HERE IS THIS BAKER<COMPONENT> CLASS
{
public override void Bake ( CupOfCoffeeAuthoring authoring )
{
Entity entity = this.GetEntity( authoring , TransformUsageFlags.Dynamic );
// note on TransformUsageFlags: https://docs.unity3d.com/Packages/com.unity.entities@1.0/api/Unity.Entities.TransformUsageFlags.html#fields
AddComponent<IsCoffee>( entity );
AddComponent( entity , new Fill{
Value = authoring.Fill ,
} );
AddComponent( entity , new Intensity{
Value = authoring.Intensity ,
} );
AddComponent( entity , new InstantiateOnDestroyed{
Prefab = this.GetEntity( authoring.InstantiateOnDestroyed , TransformUsageFlags.Dynamic ) ,
} );
}
}
}
public struct IsCoffee : IComponentData {}
public struct Fill : IComponentData
{
public float Value;
}
public struct Intensity : IComponentData
{
public int Value;
}
public struct InstantiateOnDestroyed : IComponentData
{
public Entity Prefab;
}
This Baker
class instructs how this MonoBehaviour
component is converted (baked :V) into a entity and it’s components.
This new workflow works like this:
- Open a scene
- Create a sub-scene there
- Open and fill this sub-scene with few different
gameObject
s you want to convert to entities
- Close this sub-scene to trigger baking (conversion) process to entities
- Wait a moment and look into Console for baking warnings & errors.
- Fix baking errors & hit Play.
A sub-scene looks like this. Open/Close button on the right (red square). Open shows you GameObjects
while Close triggers baking / conversion.
