Having problems with a simple Rotate System

Hi,
I feel very stupid, but I could not get that simple Rotation System to work.

Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Collections;
using Unity.Entities;
using Unity.Transforms;
using Unity.Mathematics;
using System;
using System.Runtime.CompilerServices;

public class OneRotationSystem : ComponentSystem {

    public struct CubeGroup {
        public ComponentDataArray<Rotation> cubeRotation;
        public EntityArray Entities;
        public readonly int Length;
    }


#pragma warning disable 649
    [Inject] private CubeGroup cubeGroup;
#pragma warning restore 649

    protected override void OnUpdate()
    {
        float dt = Time.deltaTime;
        float speed = 100;

        for (var i = 0; i < cubeGroup.Length; ++i)
        {
            var rotation = cubeGroup.cubeRotation[i];
            rotation.Value = math.mul(math.normalize(rotation.Value), quaternion.AxisAngle(math.up(), dt * speed));
        }
    }
}

My entities, have Position, Rotation and MeshInstanceRenderer Components. I have instantiated them and I see them in the scene, but I could not modify the rotation, I have a feeling that something is overwriting the old value every frame I try to modify it.

I am using Unity 2018.3b11 and the latest Entities version available in the Package Manager.

Thanks!

You’re only modifying a local copy of rotation.

Remember that ComponentData are structs, not a classes, so you need to apply it back.

            var rotation = cubeGroup.cubeRotation[i];
            rotation.Value = math.mul(math.normalize(rotation.Value), quaternion.AxisAngle(math.up(), dt * speed));
            cubeGroup.cubeRotation[i] = rotation;

Side note, [Inject] and ComponentDataArray are being removed so you should look into chunk iteration.

Are you sure about ComponentDataArray?

Recommend to whatch last talk of unite LA day 2 - ECS: The Evolution of the ECS API

also here you can read about other reason: Performance degradation over time due to ever increasing Archetype count - Unity Engine - Unity Discussions

I feel like it’s easier to write common tasks with Jobs than regular systems now.

IJobProcessComponentData / IJobProcessComponentDataWithEntity and substractive attributes just saving me from using Chunk iteration by hand.

using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;

[UpdateAfter(typeof(RemoveHeatingSystem))]
public class DecreaseTemperatureSystem : JobComponentSystem
{
    [RequireSubtractiveComponent(typeof(Heating))]
    private struct DecreaseTemprerature : IJobProcessComponentData<Temperature>
    {
        public float Delta;
        public void Execute(ref Temperature data)
        {
            data.Value = math.max(data.Value - Delta, 0f);
        }
    }
   
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        return new DecreaseTemprerature{Delta = Time.deltaTime}.Schedule(this, inputDeps);
    }
}

Thanks SubPixel