Sprite.Create() and RenderTexture

Hello, I need to create a sprite from render texture. I use unity official method:convert render texture to texture2D and then use Sprite.Create() - and after that use my image.sprite = texture;
But it not that texture what my other camera render… Here code:

public class Slot : MonoBehaviour
{
public Camera renderCamera;
private Sprite sprite;
private Image slotImage;

void Start()
{
    RenderTexture renderTexture = new RenderTexture(512, 512, 0);
    renderTexture.name = "Default_Texture";
    renderCamera.targetTexture = renderTexture;
    slotImage = gameObject.transform.GetChild(0).gameObject.GetComponent<Image>();
    Texture2D modelView = ToTexture2D(renderCamera.targetTexture);
    sprite = Sprite.Create(modelView, new Rect(0, 0, modelView.width, modelView.height), new Vector2(0.5f,0.5f));
    sprite.name = modelView.name;
    slotImage.sprite = sprite;
}

void Update()
{
    
}

public Texture2D ToTexture2D(RenderTexture rTex)
{
    // Remember currently active render texture
    RenderTexture currentActiveRT = RenderTexture.active;

    // Set the supplied RenderTexture as the active one
    RenderTexture.active = rTex;

    // Create a new Texture2D and read the RenderTexture image into it
    Texture2D tex = new Texture2D(rTex.width, rTex.height);
    tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);

    // Restorie previously active render texture
    RenderTexture.active = currentActiveRT;
    return tex;
}

}

You’re missing a call to Camera.Render and Texture2D.Apply. Something like this should work:

public Texture2D ToTexture2D(RenderTexture rTex)
{
    RenderTexture currentActiveRT = RenderTexture.active;
    RenderTexture.active = rTex;

    Camera.current.Render();

    // Create a new Texture2D and read the RenderTexture image into it
    Texture2D tex = new Texture2D(rTex.width, rTex.height);
    tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
    tex.Apply();

    RenderTexture.active = currentActiveRT;
    return tex;
}

Or try this extension method.

Calling Render is what writes to the render texture. Calling Apply writes the pixels into the texture.