1
TNet 3 Support / TNManager.Create'ed objects doesn't initialize
« on: June 12, 2014, 01:59:23 PM »
Hi!
I have an inventory system where I can drag anything from the inventory and into "the open", ie. the terrain, and I want the game to create a "sack" over the network and fill it whatever I'm throwing away.
Easy enough, one would think, but the problem I'm facing is that Create() doesn't behave like Instantiate, as it doesn't really instantiate the object. Consider this code, which is run whenever I drop an item (or items) into "the open."
Each ThrowAwaySack has an InventoryController attached to it, and with this code the sack itself gets created over the network just fine. However, its InventoryController is never initialized, ie. it never does Awake(), which is crucial for things to work.
With f.ex. PhotonNetwork, I could do a PhotonNetwork.Instantiate() and get an initialized GameObject back, but TNManager.Create() is void, so...?
Any help is appreciated!
Thanks!
I have an inventory system where I can drag anything from the inventory and into "the open", ie. the terrain, and I want the game to create a "sack" over the network and fill it whatever I'm throwing away.
Easy enough, one would think, but the problem I'm facing is that Create() doesn't behave like Instantiate, as it doesn't really instantiate the object. Consider this code, which is run whenever I drop an item (or items) into "the open."
- public void OnDragEnd ( dfControl source, dfDragEventArgs args ) {
- // Create a new ThrowAwaySack
- TNManager.Create( "Prefabs/ThrowAwaySack", playerCamera.transform.position, Quaternion.identity, false );
- // Populate the ThrowAwaySack's inventory
- InventoryController throwAwaySackInventoryController = throwAwaySack.GetComponent<InventoryController>();
- SlotPanelController slotPanelController = (SlotPanelController)args.Data;
- Slot sourceSlot = slotPanelController.slot;
- int itemsAdded = throwAwaySackInventoryController.AddItems( sourceSlot.items[0], sourceSlot.items.Count );
- sourceSlot.RemoveItems( sourceSlot.items[0], itemsAdded );
- // Mark as dropped
- args.State = dfDragDropState.Dropped;
- }
- }
Each ThrowAwaySack has an InventoryController attached to it, and with this code the sack itself gets created over the network just fine. However, its InventoryController is never initialized, ie. it never does Awake(), which is crucial for things to work.
With f.ex. PhotonNetwork, I could do a PhotonNetwork.Instantiate() and get an initialized GameObject back, but TNManager.Create() is void, so...?
Any help is appreciated!
Thanks!