playMaker

Author Topic: Network Destroy destroying all network instantiated objects?  (Read 5504 times)

Gevarre

  • Playmaker Newbie
  • *
  • Posts: 49
Hi,
I just found what I'm not sure is a bug or just something I'm doing wrong. I'm doing a networked game and I find that if I Network Instantiate something (for instance: a particle effect prefab with a network view) and then kill it using Network Destroy, all Network Instantiated objects in my scene are killed, including the player!

All prefabs have a network view, all view IDs at runtime are unique, nothing is parented to anything else, so I don't see any chain of events that would cause them all to die unless there is some kind of bug or some kind of setting I don't know about. This is my third networked game using Unity, so I'm pretty sure it's not something Unity-wise. Also note: I'm using straight-up Unity networking, not PUN, so that shouldn't be the issue.

Anyone else run into an issue with this? I found one forum post from 2012 mentioning that there was a bug with the Network Destroy action and that it was being fixed. Did this change ever make it into release?
« Last Edit: May 08, 2013, 03:24:20 PM by Gevarre »

Gevarre

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Network Destroy destroying all network instantiated objects?
« Reply #1 on: May 08, 2013, 05:28:56 PM »
Okay, I've checked out the script for the Network Destroy action and found the problem.

In Unity there are two commands for destroying networked objects:
Network.Destroy();
Network.DestroyPlayerObjects();

The action script is using the latter: "Network.DestroyPlayerObjects();". The way this works is that it gets the groupID of the object and destroys everything in the scene with that groupID.

The groupID is always 0 by default unless the user manually changes it. Note that this is not the same as the network ID, which is dynamically assigned upon instantiation and is unique for every network ID in the scene.

The "NetworkDestroy" action, as written, should really be labeled "NetworkDestroyPlayer" because that's what it's intended use is: cleaning up all objects created by a single player. There needs to be a second action correctly labeled "NetworkDestroy" or maybe "NetworkDestroyObject" that uses "Network.Destroy();" to only get rid of the object with the currently-selected view ID.

For now, in the NetworkDestroy.cs script in Playmaker>Actions>Network, if I change this:
Code: [Select]
Network.DestroyPlayerObjects(targetGo.networkView.owner);
to this:
Code: [Select]
Network.Destroy(targetGo.networkView.viewID);
it works in the way the label (and also the associated fogbugz help page description) seems to be describing. (The fogbugz page doesn't mention player cleanup. It just says it removes "the" object specified by the user in the action. This is not what happens.)

Further notes and considerations:
Although "Network.DestroyPlayerObjects();" implies that it cleans up after a player, that isn't necessarily how it works. As stated previously, it just looks for anything with a particular groupID. There are other reasons why someone would want to manually change the groupID. Since you can use it to filter messages, one could set projectiles to one groupID, effects to another, players to another, and so on. A more precise label would be "NetworkDestroyGroupID".

The Unity docs also state that "Network.DestroyPlayerObjects();" should only be called by the server, not by individual players to clean up their own spawned items (like projectiles), so to work in it's current state as a way to clean up players, it should probably be used in conjunction with the NetworkIsServer action, though I haven't actually tested this last bit out yet.

Sorry for the lengthy post, but I'd rather give too much info than too little. Hopefully it helps other that may be confused.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Network Destroy destroying all network instantiated objects?
« Reply #2 on: May 09, 2013, 02:28:27 AM »
Hi,

 ok, thanks for the clarifications, I made the changes locally here on our rep and I also added a NetworkDestroyPlayer as mentionned.

bye,

 Jean