Objects are deleted with PluginHost.SetGameState()
Options
Sascha
✭
Hi,
I am creating a server plugin with which I can save objects created with PUN via PhotonNetwork.Instantiate() when closing the room, so that they can be reloaded when opening the room again.
To do this, I save the GameState before the room is closed to a json file.
Then when a room is opened I deserialize the json file and load the GameStates.
For testing I create a room with PUN, join it and spawn a simple cube with PhotonNetwork.Instantiate(). The previously spawned cube is also briefly displayed, but then strangely automatically deleted.
How can I prevent that the cube is deleted again or what could be the reason?
My used RoomOptions when creating a room:
roomOptions.PlayerTtl = -1;
roomOptions.EmptyRoomTtl = 0;
roomOptions.PublishUserId = true;
roomOptions.CleanupCacheOnLeave = false;
roomOptions.IsVisible = true;
roomOptions.IsOpen = true;
The json file that is created when the room is closed:
What I also noticed is that with repeated joining of the room, there are more and more Actors even though I do nothing:
Thanks for the help
I am creating a server plugin with which I can save objects created with PUN via PhotonNetwork.Instantiate() when closing the room, so that they can be reloaded when opening the room again.
To do this, I save the GameState before the room is closed to a json file.
public override void OnCreateGame(ICreateGameCallInfo _info) { using (StreamReader file = File.OpenText(Directory.GetCurrentDirectory() + @"\test.json")) { JsonSerializer serializer = new JsonSerializer(); SerializableGameState state = (SerializableGameState)serializer.Deserialize(file, typeof(SerializableGameState)); PluginHost.SetGameState(state); } _info.Continue(); }
Then when a room is opened I deserialize the json file and load the GameStates.
public override void BeforeCloseGame(IBeforeCloseGameCallInfo _info) { SerializableGameState state = PluginHost.GetSerializableGameState(); using (StreamWriter file = File.CreateText(Directory.GetCurrentDirectory() + @"\test.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, state); } _info.Continue(); }
For testing I create a room with PUN, join it and spawn a simple cube with PhotonNetwork.Instantiate(). The previously spawned cube is also briefly displayed, but then strangely automatically deleted.
How can I prevent that the cube is deleted again or what could be the reason?
My used RoomOptions when creating a room:
roomOptions.PlayerTtl = -1;
roomOptions.EmptyRoomTtl = 0;
roomOptions.PublishUserId = true;
roomOptions.CleanupCacheOnLeave = false;
roomOptions.IsVisible = true;
roomOptions.IsOpen = true;
The json file that is created when the room is closed:
{ "ActorCounter": 1, "ActorList": [ { "ActorNr": 1, "UserId": "70a9be8b-c141-419a-b44e-7aa21627d05d", "Nickname": "Sascha", "IsActive": null, "Binary": "RGIAAAEBRAAAAAFi/3MABlNhc2NoYQ==", "DeactivationTime": "2021-08-13T12:17:13.2366268+02:00", "DEBUG_BINARY": { "1": { "255": "Sascha" } } } ], "Binary": { "19": "RGl6AAEAAAAAAAF6AANpAAAAAWLKaAAEYgZpc1ZCJmIHaQAAA+liAWNWAAw/gAAAP4AAAD+AAABiAHMABEN1YmU=", "18": "RAAAAANi+nkAAXMAA3B3aHMAA3B3aHMAMERabkJ1cmRxenNveVFLMzRDMTFwdFlIT3JITlF5dUhLSXg5ZERWdFpkSEp5SDUzcXMABmN1clNjbnMAB3hyX3Jvb20=" }, "CheckUserOnJoin": true, "CustomProperties": { }, "DeleteCacheOnLeave": false, "EmptyRoomTTL": 0, "IsOpen": true, "IsVisible": true, "LobbyId": null, "LobbyType": 0, "LobbyProperties": [ ], "MaxPlayers": 0, "PlayerTTL": -1, "SuppressRoomEvents": false, "Slice": 0, "DebugInfo": { "DEBUG_PROPERTIES_18": { "250": [ ], }, "DEBUG_EVENTS_19": { "0": [ [ 1, 202, { "6": 1935032870, "7": 1001, "1": { "Code": 86, "Data": "P4AAAD+AAAA/gAAA" }, "0": "Cube" } ] ] } }, "ExcludedActors": [], "PublishUserId": false, "ExpectedUsers": [] }
What I also noticed is that with repeated joining of the room, there are more and more Actors even though I do nothing:
{ "ActorCounter": 2, "ActorList": [ { "ActorNr": 1, "UserId": "70a9be8b-c141-419a-b44e-7aa21627d05d", "Nickname": "Sascha", "IsActive": null, "Binary": "RGIAAAEBRAAAAAFi/3MABlNhc2NoYQ==", "DeactivationTime": "2021-08-13T12:17:13.2366268+02:00", "DEBUG_BINARY": { "1": { "255": "Sascha" } } }, { "ActorNr": 2, "UserId": "dc908d36-acda-44b7-91a5-aa31c1d689a8", "Nickname": "Sascha", "IsActive": null, "Binary": "RGIAAAEBRAAAAAFi/3MABlNhc2NoYQ==", "DeactivationTime": "2021-08-13T12:19:05.6159675+02:00", "DEBUG_BINARY": { "1": { "255": "Sascha" } } } ], "Binary": { "19": "RGl6AAEAAAAAAAF6AANpAAAAAWLKaAAEYgZpc1ZCJmIAcwAEQ3ViZWIBY1YADD+AAAA/gAAAP4AAAGIHaQAAA+k=", "18": "RAAAAANi+nkAAXMAA3B3aHMAA3B3aHMAMERabkJ1cmRxenNveVFLMzRDMTFwdFlIT3JITlF5dUhLSXg5ZERWdFpkSEp5SDUzcXMABmN1clNjbnMAB3hyX3Jvb20=" }, "CheckUserOnJoin": true, "CustomProperties": { }, "DeleteCacheOnLeave": false, "EmptyRoomTTL": 0, "IsOpen": true, "IsVisible": true, "LobbyId": null, "LobbyType": 0, "LobbyProperties": [ ], "MaxPlayers": 0, "PlayerTTL": -1, "SuppressRoomEvents": false, "Slice": 0, "DebugInfo": { "DEBUG_PROPERTIES_18": { "250": [ ], }, "DEBUG_EVENTS_19": { "0": [ [ 1, 202, { "6": 1935032870, "0": "Cube", "1": { "Code": 86, "Data": "P4AAAD+AAAA/gAAA" }, "7": 1001 } ] ] } }, "ExcludedActors": [], "PublishUserId": false, "ExpectedUsers": [] }
Thanks for the help
0
Answers
-
Hi @Sasha,
Thank you for choosing Photon!
There are three (3) different points worth mentioning:
1. game objects disappearing or being destroyed, this is probably a PUN issue not related to plugins
2. instantiated network objects are saved in the room state as cached events, so they are inside "Binary":{19:"here_in_this_base64_encoded_binary_serialized_string"
3. you need to use the same UserId per player and call RejoinRoom when you want to rejoin a room. See Room Persistence Guide.
Also you need to be aware that persisting room state and loading it may not restitute PUN's state completely.0 -
Thank you very much for the help. After I fixed the rejoining, the objects are no longer destroyed.
Now I noticed that the last transform data (position, rotation, scale) are not saved in the SerializableGameState. Is that correct?
Is there a way to get this data with the server SDK when closing a room so that I can also save them?0 -
Is there another way to get the transform information of the spawned objects on the server?0