SceneObject does not work for Webplayer

Options
I tried to instantiate sceneobject and it looked like it works, but when I start game in Webplayer, these instantiated objects are visible only for the master client.

Comments

  • Tobias
    Options
    Anything in the logs?
    Only the Master Client of a room can use InstantiateSceneObject().
  • Nothing.
    The master client used it.

    The problem occurs when I use "OnPhotonSerialize" in my own script attached to it.
    Its content is the following:
    using UnityEngine;
    using System.Collections;
    
    public class NetworkMob : Photon.MonoBehaviour {
    
    	private Vector3 realPos = Vector3.zero;
    	private Quaternion realRot = Quaternion.identity;
    	private Animator _animator;
    	private NPCStats _stats;
    
    
    	private bool _activated = false;
    
    	void Awake() {
    		_animator = GetComponent<Animator> ();
    		_stats = GetComponent<NPCStats> ();
    	}
    
    	void Start() {
    		Debug.Log ("Starting mob: " + name);
    	}
    
    	// Update is called once per frame
    	void Update () {
    		if (photonView.isMine && !_activated) {
    			//Activate NavMesh agent
    			GetComponent<NavMeshAgent>().enabled = true;
    			Debug.Log("[NetworkMob] Activating NavMeshAgent");
    			GetComponent<AI>().enabled = true;
    			Debug.Log("[NetworkMob] Activating AI");
    
    			_activated = true;
    		}
    
    		if (!photonView.isMine)
    		{ //smoothing movement
    			
    			transform.position = Vector3.Lerp(transform.position, realPos, Time.deltaTime * 5);
    			transform.rotation = Quaternion.Lerp(transform.rotation, realRot, Time.deltaTime * 5);
    		}
    	}
    	
    	void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    	{
    		if (stream.isWriting) {
    			stream.SendNext(_stats.PlayerHP);
    			stream.SendNext(transform.position);
    			stream.SendNext(transform.rotation);
    		} 
    		else { //receiving position, updating our version
    			_stats.PlayerHP = (int)stream.ReceiveNext();
    			realPos = (Vector3)stream.ReceiveNext();
    			realRot = (Quaternion)stream.ReceiveNext();
    		}
    		
    	}
    }
    
  • Tobias
    Options
    Please import PUN into a new, empty project. Open the Demo Boxes scene and build it for webplayer. It has a "Scene" button, which allows you to instantiate objects as scene objects. Try to reproduce the issue with that setup, please. If you can, let me know how, so I can fix things.
    Then I also need to know which version of Unity you use to export.

    "[...] these instantiated objects are visible only for the master client."
    This sounds like it could be a positioning issue, too. Run the webplayer as master client and the Editor as second client. You can then see the log (any errors?) or select the objects in the hierarchy to see where they are (maybe they are invisible, because the position is wrong).
  • My apologies, it does work. There was a logical mistake in my code (photonView.isMine instead of PhotonNetwork.isMasterClient), I expected it would have the same effect in this specific matter, but it did not.