Register render - Antoshidza/NSprites GitHub Wiki

We need to tell system how to render sprites, meaning what material it should use and with what component properties. In general all we need is to pass unique ID, Material and set of properties IDs with PropertyUpdateMode.

The easiest way is:

// access to system singleton to register data
if (!SystemAPI.ManagedAPI.TryGetSingleton<RenderArchetypeStorage>(out var renderArchetypeStorage))
    return;

renderArchetypeStorage.RegisterRender
(
    renderID,           // unique render ID
    material,           // material with [Enable GPU Instancing] enabled and shader supporting instancing
    new PropertyData[]  // properties set
    {
        new PropertyData("_pos2D", PropertyUpdateMode.Reactive),
        new PropertyData("_color", PropertyUpdateMode.Static),
    }
);

But in the end system wants to get PropertyData[] which is just struct with int for shader's property ID and PropertyUpdateMode for update mode fields. You can prepare it somewhere in your project and pass as array to avoid extra Shader.PropertyToID(string).

There is also three additional optional parameters:

  • MaterialPropertyBlock - system uses instance of this class to set ComputeBuffer to Material, so if you want some custom override pass your instance. But don't destroy it until rendering process goes, any buffer allocation will require valid MaterialPropertyBlock.
  • InitialCapacity - it is simply how many elements space allocated at first buffers allocation. Scale it if you know how much sprites you can have in your project.
  • CapacityStep - minimal required capcity step, which means when any reallocation happens (to extand buffers on exceed) additional space can't be lower then capacity step.