Author Topic: Destroy player objects on leave?  (Read 2594 times)

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Destroy player objects on leave?
« on: October 21, 2014, 11:55:03 PM »
How does one destroy objects that belong to a player that just left the channel? For the moment, I have a script that is the host manager, and as it suggests, if you're hosting the game and the player leaves, it's supposed to clean up the mess left behind by the player that disconnected. Unity's Networking had a function like Network.DestroyPlayerObjects(), but I only can see in TNet that its Destroy only destroys single objects.

Or is it if I do Destroy(Player) that it will kill everything related to that player? I know I must be overlooking something but at least it's better to ask than waste time trying to run around in circles.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Destroy player objects on leave?
« Reply #1 on: October 22, 2014, 06:01:29 AM »
You don't need to do anything. When you create an object via TNManager.Create you get to specify whether it's persistent or not. By default it is, so when the player that created it leaves the object will be left behind. Pass a 'false' instead.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: Destroy player objects on leave?
« Reply #2 on: October 23, 2014, 09:04:41 PM »
You don't need to do anything. When you create an object via TNManager.Create you get to specify whether it's persistent or not. By default it is, so when the player that created it leaves the object will be left behind. Pass a 'false' instead.

The issue is that I use TNManager.Instantiate to spawn my player prefab, etc. for example:

  1. GameObject myPlayer = GameObject.FindGameObjectWithTag("Player");
  2. TNManager.Instantiate(playerRagdoll, myPlayer.transform.position, myPlayer.transform.rotation);
  3.  

The issue with TNManager.Create it doesn't allow me to set the Vector3 for position and such. Unless I have to make it, then get that reference and go from there, but that seems a little of a runaround approach. Is there a function that I can pass a bool to so that it toggle persistence?

EDIT: Brain not working, noticed there's an overload I'm not using *facepalms*
« Last Edit: October 23, 2014, 10:09:39 PM by MCoburn »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Destroy player objects on leave?
« Reply #3 on: October 25, 2014, 03:02:22 PM »
TNManager.Instantiate? There is no such thing. You are effectively using Object.Instantiate, which merely creates a local object.

TNManager.Create is what you should be using, as I said. And yes, there are several versions of it, and if you need to pass custom parameters you can also create your own custom RCCs -- check the sticky post on this forum.