Sync data without whole scene loading
Options
Hello !
Let's say I'm working on a PC 3d racing game and I want to show Speedometer / RPM on a mobile device's screen connected to the game. I don't want to sync whole scene, just to send/receive few float values. How is it possible to be done? Thanks !
Let's say I'm working on a PC 3d racing game and I want to show Speedometer / RPM on a mobile device's screen connected to the game. I don't want to sync whole scene, just to send/receive few float values. How is it possible to be done? Thanks !
0
Best Answer
-
Hi @VyacheslavK,
first of all the game client and the mobile client need to be in the same room. This shouldn't be a problem at all since you connect both clients with the same AppID. When both devices are connected to the same room you need to 'pair' them somehow. I guess in your case it is enough if the game client knows that the mobile device is ready to receive the data you want to send to it. Best way here might be to store the mobile devices PlayerID. There are different ways to achieve this, e.g. displaying the PlayerID on the mobile device and manually 'connect' the game client, e.g. having a menu option where you can enter the mobile's PlayerID which is then stored internally). When the devices are 'paired' you can start sending data to it usingPhotonNetwork.RaiseEvent(...)
function, e.g. using the following:byte eventCodeForSendingData = 1; float[] data = new float[] { speed, rpm, otherData }; PhotonNetwork.RaiseEvent(eventCodeForSendingData, data, true, new RaiseEventOptions() { TargetActors = new int[] { mobileDevicePlayerId } } );
On the mobile device you need to implement theOnEvent(byte eventcode, object content, int senderid)
event handler and display the content you received.5
Answers
-
Hi @VyacheslavK,
first of all the game client and the mobile client need to be in the same room. This shouldn't be a problem at all since you connect both clients with the same AppID. When both devices are connected to the same room you need to 'pair' them somehow. I guess in your case it is enough if the game client knows that the mobile device is ready to receive the data you want to send to it. Best way here might be to store the mobile devices PlayerID. There are different ways to achieve this, e.g. displaying the PlayerID on the mobile device and manually 'connect' the game client, e.g. having a menu option where you can enter the mobile's PlayerID which is then stored internally). When the devices are 'paired' you can start sending data to it usingPhotonNetwork.RaiseEvent(...)
function, e.g. using the following:byte eventCodeForSendingData = 1; float[] data = new float[] { speed, rpm, otherData }; PhotonNetwork.RaiseEvent(eventCodeForSendingData, data, true, new RaiseEventOptions() { TargetActors = new int[] { mobileDevicePlayerId } } );
On the mobile device you need to implement theOnEvent(byte eventcode, object content, int senderid)
event handler and display the content you received.5 -
Thanks, Christian, just one more question... On PC side I have 3d objects with Photon View assigned. They're automatically trying to appear on the mobile version. Since there are no same 3d scene in mobile version - they're trying to appear in any current active scene. What I'm doing is that immediately deleting any "new objects" inside "Update" function on mobile side. Is there any better solution for this?0
-
This is tricky, but should be possible. I guess in this case you should use manual instantiation. What you basically do is to call a RPC (you can also use RaiseEvent since you may don't have a PhotonView component to use before instantiating your 3D object) and execute it only on the PC clients. If you use RaiseEvent(...) function you can set RaiseEventOptions. Within these options you can specify TargetActors and define, who receives this raised event. This however gets a bit complex when you allow other players to join later. So the easy way might be, to raise this event for everyone and add some kind of 'decider' to your OnRaiseEvent(...) callback. Something like:
if (eventcode == yourEventCode) { if (isPcClient) { // Instantiate } else if (isMobileClient) { // Do nothing } }
If you allow other clients to join the game later on, you should buffer the instantiation as PhotonNetwork.Instantiate(...) does. You can also find this in the RaiseEventOptions. It is called CachingOption.0 -
@Christian_Simon: I have a similar purpose that to send and receive data. But RaiseEvent and OnEvent hanlder in different scenes, currently it does not work. So could you make a simple project to show me how to do, please?0
-
What exactly isn't working? Do you have any error or warning logs in the console?
Did you register OnEvent handler with something likePhotonNetwork.OnEventCall += OnEvent;
?0