Author Topic: Prefab not created even though call to TNManager.Create called AFTER joining  (Read 2455 times)

swizzersweet

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 6
    • View Profile
I'm seeing a weird issue, and I'm not sure if there's something incorrect in my methodology.

Here's the situation
1) Player A starts a game as host (and also server)
2) Player A creates an object using TNManager.Create(RobotCharacterPrefab, position,rotation, false); (works)
3) Player B connects to game, and the TNManager.Create code is hit for the previous player's created object, with correct data (prefab, position, rotation)
4) Player B cannot see the object that player A created (Does not appear in hirearchy)

If I however have both players join the same game, and then create object, it works fine

Also, what is the fourth variable "persist" in TNManager.Create? Is is the same "Persist" idea where the object will only hang around if players are in the channel?

I'm at an impasse in this issue, and before I starting debugging the create code, I'm wondering if there's something obvious I'm missing

Thanks in advance




ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
The second example that comes with TNet lets players spawn cubes by clicking. Have you tried creating a cube then joining a scene with the 2nd player? On my end the created cubes are there when I join with the second player, and everything works as expected. I'd need more details to reproduce the issue on my end.

"Persistent" flag means the object will remain in the scene after the player that created it leaves. If it's not persistent, then the object will be destroyed as soon as the player leaves.

Is "run in background" checked? Are you sure the original player didn't get disconnected, thus destroying the object?

swizzersweet

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 6
    • View Profile
Yeah I have Run in Background checked, and nobody is disconnected, I'm going to assume it's something funky in my prefab, and just start logging everything step by step

Thanks for your help

swizzersweet

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 6
    • View Profile
I figured out the issue while I was driving to dance lessons (unrelated) , and got home and tried it right away and I fixed it.

If the object isn't marked as DontDestroyOnLoad(), it may cause issues if your changing levels with a saved RFC

Series of events (may or may not be a TNet bug):

1) Player A creates hosts a game, and is the server
2) Player A switches the level using an RFC that saves the packet for others
3) Player A creates a prefab in the new level
4) Player B joins the game
5) Player B receives the prefab creation command, then loads the level, "destroying" the prefab made by player A (unexpected)

You would expect player B to receive the level loading THEN create the prefabs

In any case, an improvement in TNet would be for TNet to handle level loading separately, so users of TNet don't run into this headache, so the level is loaded first, THEN the prefabs are created

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
The problem lies in #2. You should not be switching your level via an RFC. You should be doing it via TNManager.LoadLevel.

(Create and Destroy calls always arrive before RFCs)

swizzersweet

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 6
    • View Profile
After moving to TNManager.LoadLevel and moving some hooks around, everything works now, thanks  ;)