Doubt in carrying out Transfer of ownership and control

Options

Hello Guys, good afternoon, are you ok?

I'm new to Unity and I'm developing a Moba and I'm having some difficulty with Photon Pun2.

Scenario:

My rooms are being created with RoomOptions = { CleanupCacheOnLeave = false }, it means that when someone leaves/disconnects from the room, your prefab will not be destroyed.

Problem:

In a room with 2 players (A and B, respectively) instanced, each one has its control in its independent prefab. When player B leaves the room, player A takes control of B as well as his own and for my scenario this is not cool, in some games the GameObject goes back to the spawn point and others put an AI until the player returns to the game.

I read the documentation that explains very well why this happens [Ownernship and Controll]. But I still haven't managed in any way to manipulate this transfer of control property so that it doesn't disturb player A and B's Prefab doesn't get destroyed.

I've even been thinking about creating 2 GameObject Empty, each one located at the base of both teams, so that when the player is disconnected assign control of their Prefabs to these GameObjects and make them return to the base at the expense of not affecting the gameplay of the that still remains in the room. Unfortunately I haven't been able to do that yet.

Anyway, I would like to know from you if this idea of ​​mine is valid and continue with it or if there is an even better practice to solve this problem



VIDEO: https://mega.nz/file/8RFXFLLQ#8vjC9_dYui1042m2WtYvCjlmKChF2RjoY6a_bFM8nXk

Comments

  • Tobias
    Options

    At a base level, controlling a networked object means that this client is sending the state of this object to others. It does not mean you have to apply input to it! But if the scripts on such objects are checking "IsMine", then whatever you do is applied to the object after control is transferred.

    So .. you need some other way to identify which objects you really want to move (apply input) and which ones belong to others. There is a Creator value for objects. You could check this or come up with your own logic which defines what is "your" object and which is an orphan.

    Behind the scenes, a client will still send the state updates but .. you don't have to move / apply input.