Author Topic: TNManager.CreateEx TNObject ID  (Read 2545 times)

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
TNManager.CreateEx TNObject ID
« on: July 03, 2014, 09:44:56 PM »
I have a trigger that spawns random weapons/items.  I use TNManager.CreateEx to spawn the weapons and pass some parameters over to the spawned weapon.  I changed all the TNObject IDs on the weapon so that each weapon has a different ID.  Often it spawns the same item and it says the Network ID is already in use.  I also get error messages stating:

The game object was not found in the TNManager's list of objects. Did you forget to add it?

So I add all these items to the TNManagers list.  But, when I add the items to the TNManager's list it no longer passes the parameters.  Particularly, the Items or Weapons.

This is the code I'm using:
 
  1.         [RCC(12)]
  2.         static GameObject OnCreate (GameObject prefab, Vector3 pos, Quaternion rot, Items unitName)
  3.         {
  4.                 GameObject go = Instantiate(prefab, pos, rot) as GameObject;
  5.                 ItemPickup cat = go.transform.GetChild (0).GetComponent<ItemPickup>();
  6.                 cat._thisItem = unitName;
  7.                 return go;
  8.         }
  9.        
  10.         static public void Create (GameObject prefab, Vector3 pos, Quaternion rot, Items unitName, bool persistent = true)
  11.         {
  12.                 TNManager.CreateEx(12, persistent, prefab, pos, rot, unitName);
  13.         }
  14.        
  15.         [RCC(13)]
  16.         static GameObject OnCreateWeapon (GameObject prefab, Vector3 pos, Quaternion rot, Weapons unitName)
  17.         {
  18.                 GameObject go = Instantiate(prefab, pos, rot) as GameObject;
  19.                 ItemPickup cat = go.transform.GetChild (0).GetComponent<ItemPickup>();
  20.                 cat._thisWeapon = unitName;
  21.                 return go;
  22.         }
  23.        
  24.         static public void CreateWeapon (GameObject prefab, Vector3 pos, Quaternion rot, Weapons unitName, bool persistent = true)
  25.         {
  26.                 TNManager.CreateEx(13, persistent, prefab, pos, rot, unitName);
  27.         }
  28.  
  29.         public void DropItems() {
  30.                 if (weaponsToDrop.Count > 0) {
  31.                         int loop = 0;
  32.                         for (loop = 0; loop < weaponsToDrop.Count; loop++ ) {
  33.                                 temp = (Resources.Load ("DropItems/" + weaponsToDrop[loop].Name)) as GameObject;
  34.                                 CreateWeapon (temp, itemDropTransformLocation.position, itemDropTransformLocation.rotation, weaponsToDrop[loop], false);
  35.                                 temp.rigidbody.AddForce (itemDropTransformLocation.forward * 200);
  36.                                 temp.rigidbody.AddForce (Vector3.up * 200);
  37.                         }
  38.                         weaponsToDrop.Clear ();
  39.                 }
  40.                 if (itemsToDrop.Count > 0) {
  41.                         int loop2 = 0;
  42.                         for (loop2 = 0; loop2 < itemsToDrop.Count; loop2++ ) {
  43.                                 temp = (Resources.Load ("DropItems/" + weaponsToDrop[loop2].Name)) as GameObject;
  44.                                 Create (temp, itemDropTransformLocation.position, itemDropTransformLocation.rotation, itemsToDrop[loop2], false);
  45.                                 temp.rigidbody.AddForce (itemDropTransformLocation.forward * 200);
  46.                                 temp.rigidbody.AddForce (Vector3.up * 200);
  47.                         }
  48.                         itemsToDrop.Clear ();
  49.                 }      
  50.         }

Do you know what I am doing wrong?  I am trying to pass a parameter like I would like instantiating.

Thanks for any assistance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNManager.CreateEx TNObject ID
« Reply #1 on: July 04, 2014, 03:04:37 PM »
Is that class marked as [Serializable] at least? Only serializable classes can be passed as parameters.

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: TNManager.CreateEx TNObject ID
« Reply #2 on: July 04, 2014, 03:32:19 PM »
Yes, they are.

  1.  
  2. using UnityEngine;
  3. using System.Runtime.Serialization;
  4. using System.Runtime.Serialization.Formatters.Binary;
  5.  
  6. [System.Serializable]
  7. public class Weapons : Inventory {
  8.  
  9.  
  10.  

It passes when I have all the network ID's set to zero and use TNManager.CreateEx.  However, each object has this error attached:

The game object was not found in the TNManager's list of objects. Did you forget to add it?

Thats when I added it to TNManager and gave them individual ID's.  When I add it to the TNManager, they no longer pass.

In a similar issue with trying to pass in another section of my code:

  1.  
  2.         public void SetupPistolSlot(Weapons _wpnToSetup) {
  3.                 Debug.Log (_wpnToSetup);               
  4.                 Debug.Log (_wpnToSetup.Name);           //works fine here
  5.                 if (tno.isMine) {
  6.                         tno.Send ("SetupPistolSlotCall", TNet.Target.AllSaved, _wpnToSetup );
  7.                 }
  8.         }
  9.  
  10.         [TNet.RFC]
  11.         void SetupPistolSlotCall(Weapons _wpnToSetup) {
  12.                 Debug.Log ("inside rfc");
  13.                 Debug.Log (_wpnToSetup.Name);           //returns null
  14.                 int loop = 0;
  15.                 for (loop = 0; loop < pistols1.Count; loop++ ) {
  16.                         //Debug.Log (pistols1[loop].name);
  17.                         if (_wpnToSetup.Name == pistols1[loop].name) {
  18.                                 pistols1[loop].SetActive (true);
  19.                                 pistolSlot = pistols1[loop];
  20.                         }
  21.                 }
  22.         }
  23.  
  24.  

The above code: the last debug.log _wpnToSetup.Name returns null.

Do you think my mistake is likely somewhere else in the code?  Or my setup of Tnet?
« Last Edit: July 05, 2014, 03:16:18 AM by voncarp »

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: TNManager.CreateEx TNObject ID
« Reply #3 on: July 05, 2014, 05:34:58 PM »
Ok.  I see what the issue was.  Thanks for the push in the right direction.