Writting Render Textures to sprites in U#

Hey! I’m trying to get a camera render texture onto a sprite in Udon#. The goal is to use this sprite on a particle emitter (which is why it needs to be a sprite rather than a RawImage or Material).

I have made it most of the way there with the following:

public class FireworkCamera : UdonSharpBehaviour
{
    public Camera cam;
    public Image Screen;
    public RenderTexture rt;
    public Sprite sprite;
    public UdonSharpBehaviour ImageSel;

    override public void OnPickupUseDown()
    {
        cam.Render();
    }

    private void OnPostRender()
    {
        Debug.Log("post rend");

        TakeSnapshot();
    }

    public void TakeSnapshot()
    {
        Debug.Log("snapping");
        cam.targetTexture = rt;
        Rect rect = new Rect(0, 0, rt.width, rt.height);

        sprite.texture.ReadPixels(rect, 0, 0, true);
        sprite.texture.Apply();
        //ImageSel.SetProgramVariable("SyncedArray", 0);
    }
}

The issue I’m facing is that when it writes to the provided sprite it only writes as a 4x4 pixel image.

Usually, to fix this I would create a whole new texture with the right sizing instead of using ReadPixels directly on the sprite texture, but Udon does not expose the constructor for textures.

P.S:
I did try making a sprite that was a blank PNG of the right size, but when I do that it just gives the error “Unable to retrieve image reference”

I would love suggestions on how to solve this issue!

Ah, I’m unable to give you more detailed help right now - but I thought you’d be interested in Graphics.Blit. Do you think that might be useful in your situation?

You can read more about it here: VRCGraphics