Can I use a custom C# class as field for a component ? [ECS]

Hello fellow Unity users, I’m trying to get my around the new Unity ECS system by creating a wich spawns planets entities to wich I apply some orbiting logic. I’m trying to use a custom class that I’ve created as a component field wich should be initialized on entity creating (by hand) and never touched again (apart for calculation at run time).

However, Unity don’t seem to be really fond of this.

The problem I’m facing is that I have to initialize this class on each OnUpdate() call of my OrbitMotionSystem (wich is, I believe, not good practice). Is there any way to use my custom class as a component field ?

For reference :

My OnUpdate() logic :

protected override void OnUpdate()
    {
        Entities.ForEach((ref OrbitComponent orbitComponent, ref EllipseComponent ellipseComponent, ref Translation translation) =>
        {
            Ellipse instanceEllipse = new Ellipse(ellipseComponent.xAxis, ellipseComponent.yAxis);
            // Test(orbitComponent, instanceEllipse, translation);

            
            float2 orbitPos = instanceEllipse.Evaluate(orbitComponent.orbitProgess);
            translation.Value.x = orbitPos.x;
            translation.Value.y = 0f;
            translation.Value.z = orbitPos.y;
            

            float orbitSpeed = 1f / orbitComponent.orbitPeriod;
            if (orbitComponent.orbitActive)
            {
                orbitComponent.orbitProgess += Time.deltaTime * orbitSpeed;
                orbitComponent.orbitProgess %= 1f;
                // Test(orbitComponent, instanceEllipse, translation);
                orbitPos = instanceEllipse.Evaluate(orbitComponent.orbitProgess);
                translation.Value.x = orbitPos.x;
                translation.Value.y = 0f;
                translation.Value.z = orbitPos.y;
            }
        });
        
    }

(You may notice that I’ve tried to use functions in my OnUpdate(), this doesn’t seem to work (and I’ve read that this should not). But if that seem possible to you, it would be my pleasure to hear more about this…

And what I’m excepting my EllipseComponent to look like :

public struct EllipseComponent : IComponentData
{
    public Ellipse ellipse;
}

I hope my post is not too messy. As I said, I’m really new to the ECS system and its a bit difficult for me to see beyond the classic OOP paradigm.

Thanks in advance for your answers.

You are able to keep non-blittable types and managed data in your component by defining it as a class.

 public class EllipseComponent : IComponentData
 {
     public Ellipse ellipse;
     public Mesh mesh;
 }

And here’s a full working sample:
https://github.com/UnityTechnologies/EntityComponentSystemSamples/tree/master/ECSSamples/Assets/Advanced/ManagedComponents
Be advised that managed components have many drawbacks and probably effect of/may lead to bad data-oriented design.
More info here: General purpose components | Entities | 0.4.0-preview.10

Thanks a lot for your answer. I’m reading your examples.