Author Topic: TNManager.CreateEx doubts  (Read 2617 times)

xandeck

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 54
    • View Profile
TNManager.CreateEx doubts
« on: November 24, 2015, 10:36:25 PM »
Hello,

Please, can anyone answer me a few questions =)
- Is there a way to know when CreateEx ends creating and loading everything?
- Right now, I create some characters on scene using "CreateEx", but sometimes it takes longer than I expected and then screws up

Thank you in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNManager.CreateEx doubts
« Reply #1 on: November 25, 2015, 06:21:27 PM »
CreateEx is used by everything, even TNManager.Create. What's the actual issue you're running into?

xandeck

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 54
    • View Profile
Re: TNManager.CreateEx doubts
« Reply #2 on: November 25, 2015, 09:13:58 PM »
I am using for creating characters in game, normal prefabs.
But sometimes, it takes a few more seconds, depending on the map (I assume objects in scene, loading in Unity usually) and the objects to spawn via CreateEx.

So, if one character prefab is created with CreateEx call and I just start to use RFC, sometimes it says "Trying to execute RFC #17 on TNObject #16777215 before it has been created." - this is my movement command to update in all clients. If this happens, some clients can't see this character updates (the funny point is that other RFCs work, like chat commands, just everything with this character does not).
Sometimes it works, sometimes does not.
To fix this I made all players to wait a few seconds, check some variables and then I start to send RFC for movement and anything else from these created prefabs (characters) with CreateEx. But I think it should work, right? Because if it was created, it means it exists in scene and... normal RFCs can already be send.
If I had something to tell me, as a callback or something, that the object that I sent to create, was actually created, this would be better (or maybe I am doing something wrong here).

Script to send:
  1. TNManager.CreateEx(12, false, _MissionSceneManager.Instance._charactersPrefabs[(int)_CharacterType.allyNpc], pos, rot, unitName, (int)charInfo._weaponPrimary, (int)charInfo._weaponSecondary, (int)charInfo._gadget1, (int)charInfo._gadget2);
  2.  

Script received:
  1. [RCC(12)] static GameObject _Receive_CreatePlayerCharacter (GameObject prefab, Vector3 pos, Quaternion rot, string unitName, int gun1, int gun2, int gad1, int gad2)
  2.         {
  3.                 _SaveLog("NETWORK", "NETWORK: Received creation of player character - " + unitName);
  4.                
  5.                 //Cria personagem na tela
  6.                 GameObject objCreated = (GameObject) Instantiate(prefab, pos, rot);
  7.                 objCreated.name = unitName;
  8.                
  9.                 //Pega script e cria arma para ele
  10.                 _CharacterPlayerController playerScript = objCreated.GetComponent<_CharacterPlayerController>();
  11.                
  12.                 //Pega items a dar para jogador
  13.                 _ItemData playerGun1Weapon = _ItemsManager.Instance._itemsList[gun1];
  14.                 _ItemData playerGun2Weapon = _ItemsManager.Instance._itemsList[gun2];
  15.                 _ItemData itemExtra1 = _ItemsManager.Instance._itemsList[gad1];
  16.                 _ItemData itemExtra2 = _ItemsManager.Instance._itemsList[gad2];
  17.                
  18.                 _CharacterData tempPlayer = new _CharacterData();
  19.                 tempPlayer = Instance._networkProfileActive._soldiersList[0];
  20.                
  21.                 //CHECA ERROS
  22.                 if (tempPlayer._alias == "")
  23.                 {
  24.                         _SaveLog("NETWORK", "ERROR: character to create NOT FOUND", 1);
  25.                         return objCreated;
  26.                 }
  27.                
  28.                 //Seta jogador local
  29.                 playerScript._PrepareForStartLocal(tempPlayer, playerGun1Weapon, playerGun2Weapon, itemExtra1, itemExtra2);
  30.                
  31.                 //Seta armas do HUD
  32.                 _MissionSceneManager.Instance._guiPlayerHUD_panelPrimary.sprite = _MissionSceneManager.Instance._itemSprites[(int)playerScript._characterData._weaponPrimary];
  33.                 _MissionSceneManager.Instance._guiPlayerHUD_panelSecondary.sprite = _MissionSceneManager.Instance._itemSprites[(int)playerScript._characterData._weaponSecondary];
  34.                
  35.                 //AVISA EVENTOS
  36.                 _MissionSceneManager.Instance._CallPlayerCreated();
  37.  
  38.                 //Reseta inputs
  39.                 Input.ResetInputAxes();
  40.                
  41.                 //Debug
  42.                 _SaveLog("NETWORK", "ONLINE Local player character created!");
  43.                
  44.                 return objCreated;
  45.         }
  46.  

EDIT: tried both with "SendQuickly" and "Send", same result (tried also with persistent and not, same result)
« Last Edit: November 25, 2015, 09:27:58 PM by xandeck »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNManager.CreateEx doubts
« Reply #3 on: December 01, 2015, 08:00:17 AM »
Ah, that's likely unrelated to object creation. When client A sends a packet for an object that client B has the ability to destroy (such as by leaving the channel), you can run into a case like this:

1. Client A sends a frequent packet marked as "saved".
2. Client B destroys the object, sending the destroy packet to the server.
3. Server receives #2 first, destroys the object.
4. Server receives #1, stores the RFC call.

Now players that join will still receive the RFC, even though the object has already been destroyed.

I've seen this in Windward on a few occasions but it has always been completely benign, since TNet simply ignores packets for objects that don't exist at run-time (the message you see is only for the editor). I'll likely add code that will check to see if an object has been destroyed recently, and if so the RFC will be ignored -- that'll fix the message.

But for now make sure that only the player that created the object will be the one sending packets for that object.

xandeck

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 54
    • View Profile
Re: TNManager.CreateEx doubts
« Reply #4 on: December 03, 2015, 08:25:49 AM »
Thanks for the feedback, Aren.
It is all working good now, the only point was that about the sending after a few seconds of waiting and so on.
I am already doing something like you said, thanks =)