Author Topic: ERROR Object not added to TNManager  (Read 4206 times)

ibrahim

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 10
    • View Profile
ERROR Object not added to TNManager
« on: February 15, 2016, 12:51:03 PM »
Hello Again!
i tryed to fix my game client and now giving error object not addet do TNManager did you forgot my script its

  1. [TNet.RCC(10)]
  2.         void Update()
  3.         {
  4.                 float time = Time.time;
  5.  
  6.                 // We're ready to fire -- fire the cannon
  7.                 if (mFireTime != 0f && mFireTime <= time)
  8.                 {
  9.                         // Recharge time varies from 80% to 120% of the intended duration just to add variety
  10.                         mRechargeTime = time + rechargeTime * Mathf.Lerp(0.8f, 1.2f, Random.value);
  11.                         mFireTime = 0f;
  12.  
  13.                         // Create the cannon ball
  14.                         if (cannonballPrefab != null)
  15.                         {
  16.                                 // Instantiate the prefab
  17.                                 GameObject go = TNManager.Instantiate(cannonballPrefab, mTrans.position, mTrans.rotation) as GameObject;
  18.  
  19.  
  20.  
  21.                                 if (mColliders != null)
  22.                                 {
  23.                                         Collider col = go.GetComponent<Collider>();
  24.  
  25.                                         if (col != null)
  26.                                         {
  27.                                                 foreach (Collider c in mColliders)
  28.                                                 {
  29.                                                         Physics.IgnoreCollision(c, col);
  30.                                                 }
  31.                                         }
  32.                                 }
  33.  
  34.                                 // It's usually a good idea to know who fired the cannon ball
  35.                                 Cannonball cb = go.GetComponent<Cannonball>();
  36.                                 if (cb != null) cb.owner = mStats.gameObject;
  37.  
  38.                                 // Rigidbody is generally expected to be present
  39.                                 Rigidbody rb = go.GetComponent<Rigidbody>();
  40.  
  41.                                 if (rb != null)
  42.                                 {
  43.                                         Vector2 deviation = Vector2.zero;
  44.  
  45.                                         // Deviate the aim a little
  46.                                         if (maxAimDeviationAngle > 0f)
  47.                                         {
  48.                                                 deviation = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
  49.                                                 deviation.Normalize();
  50.                                                 deviation *= maxAimDeviationAngle;
  51.                                         }
  52.  
  53.                                         // Calculate the initial velocity
  54.                                         Quaternion firingDir = Quaternion.LookRotation(mFiringDir);
  55.                                         Vector3 vel = (firingDir * Quaternion.Euler(-mFiringPitch + deviation.x, deviation.y, 0f)) *
  56.                                                 Vector3.forward * initialVelocity;
  57.  
  58.                                         // NOTE: For physics-accurate results we should append the ship's velocity as well,
  59.                                         // but this makes the auto-aiming logic fail unless the ship isn't moving.
  60.                                         rb.velocity = vel;
  61.                                         TNManager.CreateEx (10,false,go);
  62.                                 }
  63.                                 else
  64.                                 {
  65.                                         Debug.LogWarning("The cannon ball is missing its rigidbody");
  66.                                 }
  67.  
  68.                         }
  69.                 }
  70.         }

and i added my object cannonball in tnmanager how can i fix this plz .. using tnet 2.1.1

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ERROR Object not added to TNManager
« Reply #1 on: February 15, 2016, 02:24:42 PM »
Update can't be an RCC. RCC is what's used to create objects. Its return type is "GameObject", and it expects to have a GameObject (prefab) as its first parameter. Not sure what you're doing there.

ibrahim

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: ERROR Object not added to TNManager
« Reply #2 on: February 15, 2016, 02:28:27 PM »
Can you give me a way how can i make it right i already fixed it with TNManager.create() but she dont have power of throw in it stay in same place :(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile

ibrahim

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: ERROR Object not added to TNManager
« Reply #4 on: February 15, 2016, 02:42:14 PM »
Can you help me please with this im trying but awsly fail when make it throw please

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ERROR Object not added to TNManager
« Reply #5 on: February 15, 2016, 03:49:41 PM »
Help you what? That post I linked explains exactly how to do it.

1. Don't pass a game object. Pass a name of the prefab in the Resources folder.
2. Create a proper RCC function as explained in http://www.tasharen.com/forum/index.php?topic=5416.0

You seem to want me to write the code for you, is that it? Well fine, here:
  1. [RCC(10)]
  2. GameObject CreateCannonball (GameObject prefab, Vector3 pos, Vector3 vel)
  3. {
  4.         GameObject go = Object.Instantiate(prefab) as GameObject;
  5.         go.transform.position = pos;
  6.         go.GetComponent<Rigidbody>().velocity = vel;
  7.         return go;
  8. }
  9.  
  10. void Update()
  11. {
  12.         // Only the object's owner should be firing cannons
  13.         if (!tno.isMine) return;
  14.  
  15.         float time = Time.time;
  16.  
  17.         // We're ready to fire -- fire the cannon
  18.         if (mFireTime != 0f && mFireTime <= time)
  19.         {
  20.                 // Recharge time varies from 80% to 120% of the intended duration just to add variety
  21.                 mRechargeTime = time + rechargeTime * Mathf.Lerp(0.8f, 1.2f, Random.value);
  22.                 mFireTime = 0f;
  23.                
  24.                 Vector2 deviation = Vector2.zero;
  25.  
  26.                 // Deviate the aim a little
  27.                 if (maxAimDeviationAngle > 0f)
  28.                 {
  29.                         deviation = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
  30.                         deviation.Normalize();
  31.                         deviation *= maxAimDeviationAngle;
  32.                 }
  33.  
  34.                 // Calculate the initial velocity
  35.                 Quaternion firingDir = Quaternion.LookRotation(mFiringDir);
  36.                 Vector3 vel = (firingDir * Quaternion.Euler(-mFiringPitch + deviation.x, deviation.y, 0f)) *
  37.                                 Vector3.forward * initialVelocity;
  38.                
  39.                 TNManager.Create(10, "Cannonball", true, mTrans.position, vel);
  40.         }
  41. }

ibrahim

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: ERROR Object not added to TNManager
« Reply #6 on: February 15, 2016, 04:06:06 PM »
Thanks you for your time sir but seems she giving me error again but by the way thanks for your time and sory i sesturbe you ....

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ERROR Object not added to TNManager
« Reply #7 on: February 15, 2016, 04:07:35 PM »
Right rename that to CreateEx. I'm already rusty on TNet 2's syntax.

ibrahim

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: ERROR Object not added to TNManager
« Reply #8 on: February 16, 2016, 08:50:12 AM »
Hey again sir im having a new error i hope this be last check in the screenshoots please ...
i already used TNManager.ADDRCCs<cannon>(); in script awake but still giving this error

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: ERROR Object not added to TNManager
« Reply #9 on: February 17, 2016, 07:50:35 AM »
In TNet 2, the Awake script that adds the RCC needs to not be a part of the script you are trying to add. You should be adding it in another script that already exists in the scene.

It's one of many things that you no longer have to do in TNet 3.