Sprite Renderer Not work at Runtime Instance

Dev-Environment:

  • PolySpatial: 1.0.3
  • Unity 2022.3.18f

As shown below:

Code:

public Sprite Sprite;

GameObject tmp_Go = new GameObject("Sprite", typeof(SpriteRenderer));
tmp_Go.transform.SetParent(this.transform);
tmp_Go.GetComponent<SpriteRenderer>().sprite = Sprite;

Hello! Could you submit a bug report with a repro case and let us know the incident number (IN-#####)? Then we can look into it and see what might be going wrong. AFAIK, this should work fine.

How do you have different sprite renderers properly sort? It seems that sorting does not work as expected?

Between each other, SpriteRenderers should sort according to their Sorting Layer/Order in Layer properties (see Renderer.sortingOrder). If you need to enforce a sort order between SpriteRenderers and MeshRenderers or CanvasRenderers, you can use the VisionOS Sorting Group component to override the sort order.

We override the material render queue.

The sample code:

SplitImageAction.SortLayer();
int tmp_LayerIdx = 0;
foreach (GameObject tmp_GameObject in SharedGameData.Instance.ImagePart)
{
    tmp_GameObject.GetComponent<Image>().material.renderQueue = 3099 - tmp_LayerIdx;
    tmp_LayerIdx++;
}

Thanks. It’s working now. I deleted the Library folder and re-open. It’s working.

1 Like