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



