Different results when using class vs struct in Unity ECS

So I have the following code like this

protected override void OnUpdate()
        {
            var deltaTime = Time.deltaTime;
            foreach (var e in GetEntities<Components>())
            {
                if (e.Path.Coords == null || e.Path.Coords.Count == 0) continue;

                var target = e.Path.Coords.Peek();
                var tolerance = e.Path.Roads.Peek().Width;
                var coord = e.Position.Coordinate;
                if (coord.X != target.X)
                {
                    coord.X = target.X > coord.X
                        ? Mathf.Clamp(coord.X + deltaTime, coord.X, target.X)
                        : Mathf.Clamp(coord.X - deltaTime, target.X, coord.X);
                }
                /* Code is repeated for Y and Z */
                
                if (coord.Equals(target, tolerance))
                {
                    e.Path.Coords.Pop();
                    e.Path.Roads.Pop();
                }
                // I believe this is redundant when coordinate is a class
                e.Position.Coordinate = coord;
                e.Transform.position = coord.ToVector3(1.05f);
            }
        }

When Coordinate is a class, this code breaks when there are more than two in the GetEntities…, It compiles but will get stuck in a loop where it assigns coord.X a value, but on the next loop I check it is back to the original, but it works fine when it is a struct.

Evidently I’m using the new Unity ECS. To my knowledge, this result shouldn’t matter in regular code, but for some reason it’s being wacky. Any ideas on why it does this? Or am I just having a brain fart and it also happens outside of ECS?

As far as i understand ECS, they use the Job system, which means multithreading. Classes are ref types while structs are value types. Passing a ref trough multithreaded jobs is not a good idea because of concurency, unless you know what you are doing.

@madks13
I figured that, but right now this onupdate is the only thing that makes any changes to the “Position” component, everywhere else only has read access. It shouldn’t have any concurrency issues it a regular multithread. Thanks for the insight though