Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all articles
Browse latest Browse all 8947

Transfership set to scene but gameobject still gets destroyed when master client leaves

$
0
0
Hi, I'm trying to manually instantiate a scene object and sync it's transform using Photon Transform View, everything works great and it's syncing , but the only problem I'm having is even after setting the gameobjects ownership to 0 (scene) when I disconnect the master client who instantiated it , it gets destroyed. Here's my code:

IEnumerator spawm(float starttime)
{
...
...
...
PhotonView photonView = this.GetComponent ();
int id = PhotonNetwork.AllocateViewID ();
if (PhotonNetwork.isMasterClient)
photonView.RPC ("spawnNetwork", PhotonTargets.All, a, directionPos, pos, euler, id);
...
...
...
}

[PunRPC]
void spawnNetwork(int a, int directionPos, Vector2 pos, Vector3 euler, int id){

_tr = Instantiate (_pre [a]).transform; //instantiate the fish
_tr.position = pos;
_tr.eulerAngles = euler;
if (PhotonNetwork.isMasterClient) {
_tr.GetComponent ().enabled = true;
_tr.GetComponent ().enabled = true;
}
_tr.GetComponent ().viewID = id;
_tr.GetComponent ().TransferOwnership (0);

}
I understand I can use Photon.InstantiateSceneObject, but the game I'm working on is a single player game template that I bought and that I'm trying to convert to multiplayer and moving so much enemy prefabs to the Resources folder ends up breaking scripts. As a noob it took me two full days to figure out how to sync them and I've learned alot and how powerful Photon can be if used the right way and I'm loving it :).. so just wanted to see if anyone had any advice on how to keep those instantiated gameobjects in the game even when they're owned by the scene. Thanks!

Viewing all articles
Browse latest Browse all 8947

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>