Render Texture not working on phone

Hello everyone,
So here’s my problem, I’m trying to pass on a texture 2D a render texture that i’ve created, so then I can changed the texture 2D to a png, and then send this png via social media.
I’m doing my render texture with a second camera that will see a custom UI that I modify to fit the username of the player just before rendering and sending the picture.
When I activate it on my PC (via a button) it works perfectly and send this:


But when I do the same on my phone, it send this weird stuff :

I have no idea why it’s doing it.

The phone I use is a OnePlus 6 on Andoird 11
Parameters of the second camera used for rendering :


Parameters of the render texture:

And here is the code I use for all of this :

public IEnumerator CreateSharedStat()
    {
        yield return new WaitForEndOfFrame();

        //Get the player info
        PlayerInfo player = FindObjectOfType<PlayerService>().getPlayer();

        if(player != null)
        {
            username.text = player.username;
            gold.text = "Gold : " + player.nbGold.ToString();
            xp.text = "XP : " + player.nbXp.ToString();
            totalScore.text = "Total Score : " + player.totalAllScore.ToString();
            levelCompleted.text = "Levels Completed : " + player.levelList.Length.ToString();

            if (player.country.flagUrl != null && player.country.flagUrl.Length != 0)
            {
                UnityWebRequest request = UnityWebRequestTexture.GetTexture(player.country.flagUrl);
                yield return request.SendWebRequest();
                if (request.isNetworkError || request.result == UnityWebRequest.Result.ProtocolError)
                    Debug.Log(request.error);
                else
                {
                    Texture2D texture = ((DownloadHandlerTexture)request.downloadHandler).texture as Texture2D;
                    country.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2());
                }
            }
        }
        else
        {
            username.text = ".....";
            gold.text = "Gold : .....";
            xp.text = "XP : .....";
            totalScore.text = "Total Score : .....";
            levelCompleted.text = "Levels Completed : .....";
        }

        //Render the texture
        RenderTexture currentRT = RenderTexture.active;
        RenderTexture.active = OffscreenCamera.targetTexture;
        OffscreenCamera.Render();

        Texture2D sharedScreen = new Texture2D(OffscreenCamera.targetTexture.width, OffscreenCamera.targetTexture.height);
        sharedScreen.ReadPixels(new Rect(0, 0, OffscreenCamera.targetTexture.width, OffscreenCamera.targetTexture.height), 0, 0);
        sharedScreen.Apply();

        byte[] bytes = sharedScreen.EncodeToPNG();
        File.WriteAllBytes(pngFilePath, bytes);

        new NativeShare().AddFile(pngFilePath)
            .SetSubject("Golden Georges").SetText("Super Freestyle Moment").SetUrl("https://github.com/yasirkula/UnityNativeShare")
            .SetCallback((result, shareTarget) => Debug.Log("Share result: " + result + ", selected app: " + shareTarget))
            .Share();

    }

Thanks for your help

What happens if you set the filter mode to point?

Well.

https://docs.unity3d.com/ScriptReference/Texture2D.ReadPixels.html

I’d hazard guess that the format is not the same.

Try using Graphics.Blit instead.

I can’t seem to find how to use graphics.blit. In the doc it says it’s for passing a texture to a render texture, but I want to do the opposite, and I can’t find anything else than read pixels to do it.

If you have any idea on how I can pass a render texture to a texture 2d with graphics.blit I’ll gladly take it, because at this point I don’t know what to do.

Also, I wanted to point out that this method was working on my phone before, but one of my collaborate started adding URP, and it stoped working after it. It maybe isn’t the problem (because I hadn’t tested the code in a while), but I don’t see why it wouldn’t work now.

I’ve also try it and still doesn’t work

Okay finally managed to find the problem, one of my collaborator has created a script and put it on every camera, and I don’t know why but it caused the screenshare to bug on my phone.
I’ve removed it and know it works perfectly.
Thanks for all of you for the help.

1 Like