Current project I am working on is 2D and i don’t need any of the transform components on my entities. I have my own simple versions of them.
I was wondering if there is any way to disable transform conversion system? Removing transform part of Entities package would also be acceptable since i don’t need any of the components.
You can remove the components from entities that you dont need.
Localtoworld needs to exist for rendermesh to work, but the other components like translation, rotation and svsle can be removed to prevent conversion.
You can add simple GO conversion system which runs in GameObjectBeforeConversionGroup before TransformConversion. Unity’s TransformConversion is private, so you can’t use [UpdateBefore] attribute, but you can write [UpdateInGroup(typeof(GameObjectBeforeConversionGroup), OrderFirst = true)] with OrderFirst, so it will be forced to go before TranformConversion.
Unfortunately, ConvertGameObjectToEntitySystem uses Transforrm just as pointer to gameobject, so after you remove it, you can no more use IConvertGameObjectToEnity and should write GameObjectConversionSystem for every case.
This script will prevent all Transform conversions, but you can add any tags to filter exclusion.
using Unity.Entities;
using UnityEngine;
[UpdateInGroup(typeof(GameObjectBeforeConversionGroup), OrderFirst = true)]
public class SpriteRendererExcludeTransformsConversionSystem : GameObjectConversionSystem
{
private EntityQuery _transformQuery;
protected override void OnCreate()
{
base.OnCreate();
_transformQuery = GetEntityQuery
(
ComponentType.ReadOnly<Transform>()
);
}
protected override void OnUpdate()
{
EntityManager.RemoveComponent<Transform>(_transformQuery);
}
}
UPD: I’ve realised, that it is possible to write more clever system, which will trigger IConvertGameObjectToEntity on gameobject through ConvertToEntity component when there is no Transform component anymore.
public class StandbyConvertGameObjectToEntitySystem : GameObjectConversionSystem
{
void Convert(Component component, List<IConvertGameObjectToEntity> convertibles)
{
try
{
component.GetComponents(convertibles);
foreach(var convertible in convertibles)
{
var behaviour = convertible as Behaviour;
if(behaviour != null && !behaviour.enabled)
continue;
#if UNITY_EDITOR
if(!ShouldRunConversionSystem(convertible.GetType()))
continue;
#endif
convertible.Convert(GetPrimaryEntity((Component)convertible), DstEntityManager, this);
}
}
catch(Exception x)
{
Debug.LogException(x, component);
}
}
protected override void OnUpdate()
{
var convertibles = new List<IConvertGameObjectToEntity>();
Entities.WithNone<Transform>().ForEach((ConvertToEntity convertToEntityComp) => Convert(convertToEntityComp, convertibles));
convertibles.Clear();
}
}