Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Custom entity authoring behaviour for Camera object.
using Unity.Entities;
using Unity.Transforms;
using UnityEngine;
namespace Acme.Authoring
/// <summary>
/// Custom authoring way must be used because converting Camera object to Entity in traditional way (ConvertToEntity nor SubScene) does not work.
/// </summary>
public class CameraAuthoring : MonoBehaviour
private void Start()
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = em.CreateEntity();
em.SetName(entity, "Main Camera");
em.AddComponentData(entity, new Rotation()
Value = transform.rotation
em.AddComponentData(entity, new Translation()
Value = transform.position
// Taken from ConvertToEntity.InjectOriginalComponents
foreach (var com in transform.GetComponents<Component>())
if (com is GameObjectEntity || com is ConvertToEntity ||
com is ComponentDataProxyBase || com is StopConvertToEntity)
em.AddComponentObject(entity, com);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.