Hey Folks!
While implementing native sharing for mobile platforms (not the problem here), I had the idea to create a scene containing a “mockup” of the player’s progress.
My approach here was using a camera with a RenderTexture in the mockup scene, so that the mockup isn’t actually rendered on-screen.
The code for the whole process is pretty short, and looks something like this:
private IEnumerator ShareProgress()
{
yield return SceneManager.LoadSceneAsync("ProgressMockup", LoadSceneMode.Additive);
// Wait for the frame to render the mockup properly
yield return new WaitForEndOfFrame();
// Create a Texture2D from the RenderTexture
Texture2D screenshot = new Texture2D(progressMockupRenderTexture.width, progressMockupRenderTexture.height, TextureFormat.RGB24, false);
RenderTexture.active = progressMockupRenderTexture;
screenshot.ReadPixels(new Rect(0, 0, progressMockupRenderTexture.width, progressMockupRenderTexture.height), 0, 0);
screenshot.Apply();
RenderTexture.active = null;
// Convert to PNG and save temporarily
string filePath = Path.Combine(Application.temporaryCachePath, "SharedProgressMockup.png");
File.WriteAllBytes(filePath, screenshot.EncodeToPNG());
// Cleanup
Destroy(screenshot);
// Unload the Mockup scene
SceneManager.UnloadSceneAsync("ProgressMockup");
// Share via NativeShare
new NativeShare()
.AddFile(filePath)
.SetSubject(LocalizationSettings.StringDatabase.GetLocalizedString(Constants.MOBILE_SHARE_TEXTS_TABLE_REFERENCE, "Subject"))
.SetText(LocalizationSettings.StringDatabase.GetLocalizedString(Constants.MOBILE_SHARE_TEXTS_TABLE_REFERENCE, "Text"))
.SetUrl("")
.SetCallback((result, shareTarget) => Debug.Log("Share result: " + result + ", selected app: " + shareTarget))
.Share();
}
While the actual capturing and sharing works great, there is something wrong with the rendering of the scene. The scene, like any other scene in the game, contains the same lighting settings and also has things like a Directional Light set up.
Here are the images (dont worry this is still early footage and not the final version, they’re also in german but of course that dosen’t change anything xD):
Editor (how it should look):
Rendered with a Directional Light (no fog, weird shadows, too dark)
Rendered without a Directional Light (no fog, correct shadows?, too dark)
I don’t really know what would be causing this. As visible in the editor the camera is just a prefab variant of the main camera, only change here is it rendering to the render texture.
As I said the lighting settings are also all the same. Even if I disabled the render texture and played that scene it still looks fine at runtime.
I appreciate any suggestions / solutions!


