Sprite Renderers Cannot be Resized at runtime

Size seems to be respected for sprite renderers on startup, but thereafter any attempt to change the size of a SpriteRenderer does not work.

To recreate the issue, create a sprite. Set the size to some custom value.
In script, reassign the .size attribute of the SpriteRenderer, and observe no change.

Is there any workaround for this?

Can you try calling MarkDirty on the sprite renderer immediately after setting the size and see if that changes anything?

unity complains: “SpriteRenderer does not contain a definition for MarkDirty and no accessible extension method MarkDirty accepting a first arg of SpriteRenderer could be found.”

Try : PolySpatialObjectUtild.MarkDirty(spriteRenderer)

This is a function that only seems to work on renderTextures.

is this related to the issue that custom shaders are also completely broken and can’t be updated at runtime?

I tested this script both in Editor and Simulator, and it appears to be working as intended (PolySpatial 1.1.6, Unity 2022.3 latest):

using UnityEngine;

public class SpriteResize : MonoBehaviour
{

    SpriteRenderer spriteRenderer;

    void Start()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
        if (spriteRenderer == null)
        {
            Debug.LogError("SpriteRenderer not found");
            return;
        }

        StartCoroutine(ChangeSpriteSize());
    }

    IEnumerator ChangeSpriteSize()
    {
        while (true)
        {
            spriteRenderer.size = new Vector2(1, 1);
            yield return new WaitForSeconds(1);
            spriteRenderer.size = new Vector2(2, 2);
            yield return new WaitForSeconds(1);
        }
    }
}

Are you using a custom shader on your sprite and not the default Unity sprite shader?

using default unity sprite, but I did realize my polyspatial was out of date. I’m in the process of updating now, but I’ll try again and see if the update fixes it. probably just an old bug. I was on 1.0.6

1 Like

Apologies… I had thought we had a general MarkDirty API and not just tied to render textures.

1 Like

thanks so much! upgrading my polyspatial and visionOS packages did the trick for resizing spriteRenderers. I checked for updates in packagemanager, so I didn’t see that there were updates. Removing and re-adding solved the issue.

1 Like