Author Topic: [TNet 3.0] Trying to execute a function ... before it it has been created  (Read 2681 times)

Quan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Since upgrading to 3.0 I have been having issues with sending data to a prefab as its being created. This worked in 2.1 fine.

When a player joins the event is triggered on all other players where they tell the new player where they are and where they are going so things sync up. When I try to do this now I get the warning:

[TNet] Trying to execute a function 'WarpToPos' on TNObject #16777214 before it has been created.

I could delay the warp call but it would mean the warping is visible to the user, also I could hide all the renders but I am wondering if there is a easier way to do this with 3.0 ?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I suggest looking at where you're calling that function. Saved RFCs won't be sent by the server until after all RCCs have been sent, however player packets can bypass this if sent directly.

Quan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
I changed from sending to the joiningPlayer to Target.OthersSaved and this has fixed the issue.

public virtual void OnNetworkPlayerJoin(int chan, Player joiningPlayer)
    {
        if (!TNManager.isHosting) { return; }
        print("ACTOR3D::Player joined");
       
        tno.Send("WarpToPos", Target.OthersSaved, transform.position, transform.rotation, aiPath.target);
    }

Is this the best way to do it, I don't plan on having to many actors running around my game on each scene.

Maybe 20 - 30 max and up to 6 players in game. Just I can imagine a burst of data each time a player joins a scene as it sends to everyone where the actors are.

But thanks again for guiding me in the right direction.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Why are you sending it in OnNetworkPlayerJoin? You're sending it as a saved packet, meaning you can send it anywhere and new players that join will receive this packet automatically already -- you don't need to send anything manually.

Quan

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
I think its because I didn't fully understand what Saved meant and instead was sending to just Others / Notsaved.

I'll update all my code as I can see this is a much easier way of doing things.

-- EDIT

Main reason for doing this is I use pathfinding for all my character movements. I was only sending mouse clicks to the server which then told everyone else to move. If a played joined half way though a move it would need to know where to start and then where to go.

I don't do any syncing while moving only when a object reaches its destination.
« Last Edit: March 17, 2016, 01:49:08 PM by Quan »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
For pathfinding, only one client should be doing the logic, then moving the unit. Unit's sync should take care of updating its position for all clients afterwards. In case of Windward, all AI is doing is set virtual joystick values (left/right, forward/back) -- which is exactly what player controlling the unit does too. Units then sync these input values with other clients as saved packets, and each client proceeds to move the unit based on these sync'd values. The position gets sync'd periodically (every few seconds) as well just to ensure that the simulation hasn't deviated too much.