- Home /
How to reflect an image uploaded to one scene to another scene
I am making a small multiplayer game in which a visitor and an uploader will join at the same time. The uploader will upload an image to their scene(https://stackoverflow.com/questions/35183253/unity3d-upload-a-image-from-pc-memory-to-webgl-app) I want this image to be visible on an image in the main game which the visitor is playing. This game will be running on a headless server and all the networking is done using Mirror.
I don't have any clues as to how to code or implement this. Any help is appreciated.
Answer by GetLitGames · Apr 29 at 02:58 PM
You should be able to send the texture sprite as an array of bytes to the server via RPC. You can google for how to convert a texture to byte array, and a byte array into a texture. This is referred to as Serialization, you can serialize it to bytes to send to the server via RPC or to store somewhere on disk. Once you have a reference to the texture in memory all you need to do is assign it to a variable that's either on a static class or a monobehavior class attached to an object where you called Don't Destroy On Load so that when you switch scenes it stays around. If you don't already have Manager/Controller type classes or Singleton pattern classes then you should look into them as well as ScriptableObjects.
Answer by VanToRiaXVII · May 04 at 02:52 PM
If you're looking to upload a picture that doesn't already exist in the game, you're gonna need to set up a web server to make that possible. You could check out upload.io, which has a simple API to upload and then visualize images. Once you have that, you need to find out a way to check when the image has successfully been uploaded so it can be displayed on the other player's screen.
I have a web server set up, it is hosted on GCP. But, I am not sure how to upload to the game. upload.io seems like a website solution, I am not sure how that will help with a unity build game? Could you possibly give me a little more insight as to what you are suggesting ??
You only need to upload an image for your game and retrieve it from the other player's client. To do that, you need to make a call from your game to upload the image to the web server. You need to build this web server to receive an image and then send it back, on-demand, to the other player.
upload.io can do that for you without having to set up a web server on your end. Everything works with APIs, so you simply have to make the call to upload it and retrieve it for the other player. It'd save you the time to set up and manage a web server.
I actually am already running a headless server which connect my visitor and uploader at the same time. Will upload.io still help automate the process of uploading and retrieving ??
Answer by Devmaster12 · Apr 30 at 05:24 PM
Is there any other approach of doing this ??
Ah I think I see part of your problem. I will add some more info.
You should be able to create a Mirror RPC with a byte[] array parameter and just call it, after converting the Texture to a byte array. On the server you convert it back into a texture. If you need to save it on the server, then write it to a file or something - you will need to google that.
Your solution seems perfect for what I am trying to do. Currently, I have a script in place which already converts the texture to byte array. Could you tell me how to create the Mirror RPC and call it, as well as the converting back into texture part ??
Converting into byte array: byte[] pngData = System.Convert.FromBase64String(dataUrl.Substring(s_dataUrlPrefix.Length));
// Create a new Texture (or use some old one?)
Texture2D tex = new Texture2D(1, 1); // does the size matter?
if (tex.LoadImage(pngData))
{
Renderer renderer = GetComponent<Renderer>();
renderer.material.mainTexture = tex;
Below is the reference with example code. I think you may want to use a Command to get it from a client to the server. Once the server has it, use a ClientRPC to send it to all the clients. https://mirror-networking.gitbook.io/docs/guides/communications/remote-actions
Your answer
![](https://koobas.hobune.stream/wayback/20220613055955im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
How to write a multiplayer game that uses a dedicated server? 0 Answers
Questions about Multiplayer and Networking? 1 Answer
OnStart ___ vs OnLobbyStart ___ methods from NetworkManager and NetworkLobbyManager 1 Answer
Do Network Messages Use UDP or TCP? 2 Answers