starter questions around ECS

I’ve watched few videos on ECS and I have few questions I can’t find the answer to, it would be a big help if somebody can explain these to me:

1- All tutorials I’ve seen use floats to store values and it makes sense for things like position and rotation, but I have few components like Health, Mana, Experience and level that can get by with integers, is there any benefit to keep using float for them?

2- In videos, quads are used to render 2D sprites, when I try that the sprites that are not square appear squished, how can I give the pixel size of the image to the quad to show it at correct pixel size on the screen?

3- I’ve tried to move the sprites behind each other depending on their y position:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.Transforms;
using Unity.Mathematics;
public class MoverSystem : ComponentSystem
{
    protected override void OnUpdate()
    {
        Entities.ForEach((ref Translation translation, ref MoveSpeed moveSpeed) => {
            translation.Value.x += moveSpeed.x * Time.deltaTime;
            translation.Value.y += moveSpeed.y * Time.deltaTime;
            translation.Value.z = translation.Value.y*.01f;

        });
    }
}

x and y work but I can’t get anything out of z.

In response to 1.
Is up to you, what custom data type you want to use.
If you want health as int, or float, is your decision.
You just need be aware of float precision error.

  1. ints are fine and probably better
    2 and 3. unfortunately 2D/sprites isn’t well supported atm so it’s a bit of work to get them behaving nicely. honestly if you’re just trying to learn you’re probably better off working on something else to get the hang of it.

Thank you both for putting my mind at ease on the variable type.
But I can’t agree on the sprites, I get that it’s too early to rely on ECS for full 2D animation but shouldn’t resizing a quad and changing z-order work as before? after all, they are shown on the screen at a size (that should be changeable) and a z-order (since I can see some are behind others). how hard it is to access those values and change them?
I was expecting something simple like: “you can’t read position inside a system and you should get y position from localtoworld…”

@KiaAzad you can rotate and scale quads. But z depth you need also handle manually.
If you make all quads at Z = 0, you will have race conditions at rendering, to which plane render on top.

great, how I go about scale a quad inside a system or job? is there a documentation I can read these things from?
by race conditions do you mean z-fighting? I didn’t notice any of that, maybe it’s because my project is set to 2D.
I can set their z location to some random value when the entities are created but my problem seems to be changing it after that.

At the current DOTS does not have sense of 2D. All is treated as 3D.

Yep, if all instances z position is set to same value, you wont be able to guarantee, which mesh to render first.

When you say having problem with changing position, does it mean they change by them self, or you don’t know how to change?

Regarding scaling, just look at Scale and NoneUniformScale components.

They are pretty much working in same manner, as any other component.

I can change the position fine, I just can’t change the z order to move them on top of each other depending on their y position. the code example in my first post should convey what I attempted to do.
I’ll try searching NoneUniformScale in the documentation thank you.

Regarding z position, unfortunately I think only way, is to do manually. At leas I am not aware of any existing automatic system behavior.

You could give FabrizioSpadaro’s sprite sheet renderer a try, it’s supposed to have y-value sorting: 200k dynamic animated sprites at 80fps - #15 by belva1234

You can also check out CodeMonkey’s tutorials of ECS on youtube. He actually goes over using 2d sprites and implements the z-sorting.