First and Second Player share camera rotation

When my second player joins both characters fall through the world and then share camera rotation. if one player leaves the other character pops back up in the world and behaves normally.

NetworkCharacter.cs
NetworkManager.cs
PlayerMovement.cs

I'm also getting 3 really weird warnings and an error.
The referenced script on this Behaviour is missing!
UnityEngine.Resources:Load(String, Type)
PhotonNetwork:Instantiate(String, Vector3, Quaternion, Int32, Object[]) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1522)
PhotonNetwork:Instantiate(String, Vector3, Quaternion, Int32) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1498)
NetworkManager:SpawnMyPlayer() (at Assets/NetworkManager.cs:213)
NetworkManager:OnJoinedRoom() (at Assets/NetworkManager.cs:200)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1616)
NetworkingPeer:OnEvent(EventData) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1466)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:76)

points to PhotonNetwork.cs:

[code2=csharp]GameObject prefabGo; //1519
if (!UsePrefabCache || !PrefabCache.TryGetValue(prefabName, out prefabGo))
{
prefabGo = (GameObject)Resources.Load(prefabName, typeof(GameObject));
if (UsePrefabCache)
{
PrefabCache.Add(prefabName, prefabGo);
}
}[/code2]

The referenced script on this Behaviour is missing!
UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)
NetworkingPeer:DoInstantiate(Hashtable, PhotonPlayer, GameObject) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2051)
PhotonNetwork:Instantiate(String, Vector3, Quaternion, Int32, Object[]) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1553)
PhotonNetwork:Instantiate(String, Vector3, Quaternion, Int32) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1498)
NetworkManager:SpawnMyPlayer() (at Assets/NetworkManager.cs:213)
NetworkManager:OnJoinedRoom() (at Assets/NetworkManager.cs:200)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1616)
NetworkingPeer:OnEvent(EventData) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1466)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:76)

and
The referenced script on this Behaviour is missing!
UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)
NetworkingPeer:DoInstantiate(Hashtable, PhotonPlayer, GameObject) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2051)
NetworkingPeer:OnEvent(EventData) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1521)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:76)


Point to NetoworkingPeer.cs:
[code2=csharp]this.StoreInstantiationData(instantiationId, incomingInstantiationData);

// load the resource and set it's values before instantiating it:
// Debug.Log("PreInstantiate");
GameObject go = (GameObject)GameObject.Instantiate(resourceGameObject, position, rotation); //2051
// Debug.LogWarning("PostInstantiate");[/code2]


The Error is:
NullReferenceException
UnityEngine.Animator.SetFloat (System.String name, Single value) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/AnimatorBindings.cs:176)
NetworkCharacter.OnPhotonSerializeView (.PhotonStream stream, .PhotonMessageInfo info) (at Assets/NetworkCharacter.cs:56)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
PhotonView.ExecuteOnSerialize (.PhotonStream pStream, .PhotonMessageInfo info) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:243)
NetworkingPeer.OnSerializeRead (ExitGames.Client.Photon.Hashtable data, .PhotonPlayer sender, Int32 networkTime, Int16 correctPrefix) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3038)
NetworkingPeer.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1516)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (System.Byte[] inBuff)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands ()
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands ()
PhotonHandler.Update () (at Assets/_IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:76)

points to:
[code2=csharp]realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
anim.SetFloat("Speed", (float)stream.ReceiveNext()); //Line 56
anim.SetBool("Jumping", (bool)stream.ReceiveNext());
anim.SetBool("attack", (bool)stream.ReceiveNext());[/code2]

Most of this code was borrowed from quill18creates MultiplayerFPS tutorials and some of the animation stuff I was learning from the official mecanum tutorial video on the unity site.

Comments

  • If it's the same issue, this seems to be coming up a lot recently, but did you disable the controller and camera of non-controlled players? So on your prefab, disable everything that only 1 player should control, for example the camera and movement controller. Also disable the camera rotation on the camera that is in your prefab, not just the scripts on the character.

    When you instantiate it, enable those scripts for the local player, so check if the photonview is the local player's, if(photonView.isMine) and if it is then enable the scripts.

    Most of the errors you have are missing script errors. Did you check your objects/prefabs to make sure that the proper scripts are attached? If you imported objects without the scripts the links may be broken. Select your prefab or object, look in the inspector to see if it has the correct scripts or if there is "Missing" field anywhere, and if there are missing ones drag in the proper script.

    I think in the final bit of code you could change:
    [code2=csharp]GameObject go = (GameObject)GameObject.Instantiate(resourceGameObject, position, rotation);[/code2]

    to:
    [code2=csharp]GameObject go = (GameObject)Instantiate(resourceGameObject, position, rotation);[/code2]

    Not sure if that would fix your issue, but don't know why you'd have GameObject.Instantiate there.
  • i think you're on the right track with the first part. I had in the script to enable mouselook and such but also had them on in the prefab. now it's still super goofy though. when 2 characters are spawned whichever character has focus has mouse y working, but mouse x and all movement keys get played through the other character ....

    I got rid of the 3 warnings by reimporting all and then removing the bad scripts. i still have the animation error though.
  • Make sure both scripts are disabled on the prefab, (and any objects that exist in the world) and then enable them when you instantiate the object only for the local player. It sounds like you're enabling them after the instantiate, but maybe not the right scripts.

    I'm not entirely sure why you're getting a null reference for the last part. Is the stream sending over the float properly? Or is "Speed" a matching string? If the other string reference is "speed" instead of "Speed" I guess that could cause it.
  • in the animator it's definitely Speed and it seems to be working so that's weird. I went back to the tutorial I was building off of and the code there to enable scripts seems to work just fine

    It's in network manager
    [code2=csharp]void SpawnMyPlayer() {
    AddChatMessage("Spawning player: " + PhotonNetwork.player.name);

    if(spawnSpots == null) {
    Debug.LogError ("WTF?!?!?");
    return;
    }

    SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
    GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
    standbyCamera.SetActive(false);

    //((MonoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true;
    ((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
    ((MonoBehaviour)myPlayerGO.GetComponent("PlayerMovement")).enabled = true;
    ((MonoBehaviour)myPlayerGO.GetComponent("PlayerShooting")).enabled = true;
    myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);
    }[/code2]

    the biggest thing I've changed is the player model and animations. (which was a bitch) but it doesnt seem to be working in my version
  • So now it's all working except for the animation error? The only thing I can think of with the player model and animator is making sure that the animations are linked to the object in the Animator component. There's an array that might be missing the animation, though if you say the animation is working it's going to be there.
  • what i mean is the script warnings are now gone. the animation error still shows up despite animations seem to work despite that, but the big big problem is my input still goes to the wrong player except for mouse y which goes to the correct player.
  • What components do you have enabled and disabled in the inspector for the player prefab? And both players are being spawned through SpawnMyPlayer, correct?
  • in the player prefab I have very little turned on by default http://i.imgur.com/8yoP4SH.jpg pretty much just character controller (which turns itself on every time I run it anyways), networkcharacter, audio source, animator, and the photon view and ridged body which cant be turned off. yes both players spawn through SpawnMyPlayer as it was in the tutorial i'm trying to duplicate.
  • The character controller script is most likely the culprit. It takes input and applies it to the char it's on, right?
    So any input you make is applied to each and every char that's instanced, which moves all chars at the same time, obviously.
  • Tobias wrote:
    The character controller script is most likely the culprit. It takes input and applies it to the char it's on, right?
    So any input you make is applied to each and every char that's instanced, which moves all chars at the same time, obviously.

    that character controller script is from the same tutorial i'm following with working multiplayer.
  • Check if the tutorial enables the script at some point. If so, make sure in your case it's also disabled to begin with.
  • Tobias wrote:
    Check if the tutorial enables the script at some point. If so, make sure in your case it's also disabled to begin with.
    the character control script ,PlayerMovement.cs, gets enabled in the tutorial i'm following exactly the same as i'm doing. it's the same file getting enabled at the same time. it works in the tutorial but not in my scene
  • It gets enabled there but is it disabled in the beginning?
  • Tobias wrote:
    It gets enabled there but is it disabled in the beginning?
    yes http://i.imgur.com/NSY7Fgt.jpg
  • I have to admit, I don't know what's happening.
    I would have to browse through the stuff. Maybe I can do that next week.
    If you are ok sharing this with us at Exit Games, upload a package somewhere and send us the link to: developer@exitgames.com
  • Tobias wrote:
    I have to admit, I don't know what's happening.
    I would have to browse through the stuff. Maybe I can do that next week.
    If you are ok sharing this with us at Exit Games, upload a package somewhere and send us the link to: developer@exitgames.com

    I'd love too. i'll stick it in my dropbox and post a link here when it's done