Author Topic: Odd occurrence on second player client join - 2nd player takes 1st player place.  (Read 2230 times)

tstack

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 12
    • View Profile

Hello,

I can play as a single player, then join with a second device/client. But when I join with the second client, my character, name color and all appears, then shifts to where player one was on the 2nd client screen and I cannot control them.

Any thoughts here appreciated, my project is due in just over a week now.

Thanks,
tstack

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
I think what's happening is your camera is on the player prefab, and so when the second player joins Unity starts rendering the newly-spawned second camera. If that's correct then you've got a few options:
1. Decouple the camera from the player prefab (you'd have to write some code to position the camera accordingly, probably not ideal)
2. Delete the camera from the prefab on spawn if tno.isMine is false (make the camera its own child gameobject so you can do this in one simple Destroy() call from the Awake event)
3. Adjust the camera's depth property (this controls the order cameras are rendered in)

Keep in mind that each camera in the scene is rendered at all times, so option 3 probably isn't ideal. I personally go with option 2, but it feels wrong so maybe someone else has a better solution?

tstack

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 12
    • View Profile

Hi thanks cmifwdll - these are great insights - the prefab is not coupled to the camera however, it attaches after TNet instantiation - it is the same way the TNet demo files work.

Also, I should add that I got this working around March and TNet has worked flawlessly ever since. However I made changes to my game at the end of August, then went on an entire month fixing the inventory system.

I don't think I tested those August changes before I worked on the inventory system. They included things like adding a player name and the player selecting a color.

Why it suddenly applies to the 1st player on the joining client (from the 1st player client this is not indicated - everything still looks normal) I am guessing because of my handling of variables.

The game, having applied the name and color to the 1st player on the 2nd players client screen (iOS) never actually instantiates the 2nd player. I am guessing it errors out at this point.

I'm not sure what to do since feedback from the iOS platform is minimal. I am going to try commenting out my "Options Menu" code from August.





lynohd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Shouldnt just enabling/Disabling components accordingly do the trick?

  1. if(tno.IsMine)
  2. {
  3. CameraComponent.enabled = true;
  4. }else {
  5. CameraComponent.enabled = false;
  6. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You'll need to post some code of what you're doing, but as cmifwdll said you're likely simply not doing a proper check on start.