Author Topic: Instantiating clones of GameObjects in the TNManager array  (Read 2855 times)

TheGreenBamboo

  • Guest
Instantiating clones of GameObjects in the TNManager array
« on: January 12, 2014, 11:47:27 PM »
Hello there,

In my game, monsters drop items when killed. These items are obviously instantiated across all connected players (TNManager.Create()) in order for them to see it on the ground. Now when a players goes to pick it up, a clone of the item is made first (GameObject.Create()) and put into their inventory, then the original item is destroyed across all connected players (TNManager.Destroy()) so that no one can pick it up again.

Now the problem occurs when the player who pick up the item tries to drop it onto the ground again. Obviously, the item will need to be instantiated across all connected players again to be visible (TNManager.Create()). However, this throws an error as the item is not the same item prefab that's originally referenced in the TNManager item array (remember that it was cloned). The item also already has a TNObject script with a unique id on it. How would I about solving these two problems?

I'm doing the above method instead of just disabling and then enabling when the item is visible/not visible without destroying/creating for performance reasons. Players can have 50 or so items in their inventory, so having a lot of connected player without the above mentioned method means keeping a lot more GameObjects than they need to.

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Instantiating clones of GameObjects in the TNManager array
« Reply #1 on: January 13, 2014, 06:31:17 PM »
I would suggest you having items reference prefabs using their path name in the Resources folder rather than direct references to the prefab itself. As long as the object is in the Resources folder, TNet can instantiate it.