All network instantiated objects in the scene recreate upon player joining game.

Options
Hello, I seem to be having an issue with my game. I'm fairly new to PUN so forgive me if I'm missing something obvious.

Okay, time for a rundown.

I have a rocket launcher, which creates a rocket across the network(PhotonNetwork.Instantiate) when the player presses left mouse. This all works perfectly with no issues, and the damage with the explosion works flawlessly, as well. Once the rocket is spawned, it flies forward and once it collides with an object it destroys itself and creates and explosion across the network.

Again, all this works perfectly. Then, when a player rejoins--of course after joining the game first, leaving, and then rejoining that server--the game it recreates ALL of the explosions that had been created, it might even recreate other network instantiated objects, I haven't checked that. This causes the game and the server to lag out for around 5-10 seconds whilst all the explosions are being created and removed. This is of course a huge problem, as no one wants a random explosion being created on the map and potentially killing them. And imagine if we had 16 players in game, creating say 2 rockets every 3 seconds. They continue to the point where they have successfully created 8000 rockets, which have been created, and destroyed. Then, a player leaves and rejoins. Suddenly all the players jump 10 feet out of their chairs as their speakers blast with the sound of 8000 explosions happening at once, not to mention the lag or crashing their program that may be occurring on their copy of the game.

As you can see this is nothing fun, and I don't have a clue why it's happening. I have no RPC's using PhotonTargets.AllBuffered; which I figured would be the problem because it's creating it for the current players in the server and all players that join, correct?

I hope you can help me solve this, as until then I'll be disabling rocket launchers( if that's even the cause... :/ ), which ruins and removes a lot of the fun. :(

Thanks for your time!

Comments

  • vadim
    Options
    Hi,

    Do you destroy explosion objects after explosion finished? Do you use PhotonNetwork.Destroy for every object created with PhotonNetwork.Instantiate?
  • micahlg
    Options
    vadim said:

    Hi,

    Do you destroy explosion objects after explosion finished? Do you use PhotonNetwork.Destroy for every object created with PhotonNetwork.Instantiate?

    No; I have a script that destroys and the gameobject with a certain amount of time that you put in. I have a bool called "Network Instantiated" that decides whether not it destroys it across the network. I've stopped using it because every time I destroy some across the network it gives me an error that it failed to "network-remove".

    Is this the cause of it?
  • vadim
    Options
    I don't understand purpose of "Network Instantiated" bool.
    Simply call PhotonNetwork.Destroy() once on same client which called PhotonNetwork.Instantiate() for this object. All instances on all clients will be destroyed automatically.
  • micahlg
    Options
    vadim said:

    I don't understand purpose of "Network Instantiated" bool.
    Simply call PhotonNetwork.Destroy() once on same client which called PhotonNetwork.Instantiate() for this object. All instances on all clients will be destroyed automatically.


    Thanks, I now delete them with PhotonNetwork.Destroy(). The reason for the "Network Instantiated" bool is for local objects. If I just instantiate an object, not using PhotonNetwork.Instantiate, or using and RPC, it just creates it locally. The script basically just destroys the object that it's attached to with a certain amount of life time. So if I created a local object, I turn Network Instantiated to false.