ERROR You have missing MonoBehaviours on your gameobjects!
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
ERROR You have missing MonoBehaviours on your gameobjects!
Necka
2021-04-23 16:13:42
Hello,
So after literally days of troubleshooting this issue, I'm giving up and want to try getting some help here.
Unfortunately, I searched this error here and didn't really get an answer for my issue.
I'll try to put as much context as I can to avoid that you miss important information to help me:
Scenes setup:
"A": Main Menu scene
"B": Lobby Scene
There is then a play scene but this doesn't matter anymore as the error only comes in the lobby scene because of the first Player models instantiation.
In Scene "A", Player 1 through the UI can create a room. there are no Photon involved here, clicking on the Create room button setup a bunch of variables and Load Scene "B"
In Scene "B", Player 1 through a lobby script, creates the Room. Then in the network manager it uses the photon Callback
public override void OnJoinedRoom()
In there it checks if we are Master Client, if yes we setup some room props and trigger then the instantiation of the Player Prefab using of course:
PhotonNetwork.Instantiate()
From the point in time, everything works perfectly fine
At this point, Player 2 decides to join the game. Same, Scene "A", only UI without any photon magic in this scene, it just save the room name variable and Load Scene "B" (I tried with PhotonNetwork.LoadLevel("sceneName") too)
In that scene Player 2 Join the room and that's where the disaster starts!
As soon as we join the room I get the error message. I know the error is longer that usual but I added some stuff in the Debug.Log to try to pin point what RPC was the cause from where to who etc.
ERROR You have missing MonoBehaviours on your gameobjects!|| And that is this RPC: UpdateCharacter|| Sender is: #01 'Necka' || Receiver might be: [1001] Photon_Player_Base_V1 - Remote [MasterClient]
UnityEngine.Debug:LogError (object)
Photon.Pun.PhotonNetwork:ExecuteRpc (ExitGames.Client.Photon.Hashtable,Photon.Realtime.Player) (at Assets/____Assets/__Asset Store/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:473)
Photon.Pun.PhotonNetwork:OnEvent (ExitGames.Client.Photon.EventData) (at Assets/____Assets/__Asset Store/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2210)
Photon.Realtime.LoadBalancingClient:OnEvent (ExitGames.Client.Photon.EventData) (at Assets/____Assets/__Asset Store/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3336)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer) (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PeerBase.cs:891)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/EnetPeer.cs:558)
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PhotonPeer.cs:1837)
Photon.Pun.PhotonHandler:Dispatch () (at Assets/____Assets/__Asset Store/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:223)
Photon.Pun.PhotonHandler:FixedUpdate () (at Assets/____Assets/__Asset Store/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:149)
As previously stated, here Player 2 through the OnJoinedRoom() Photon callback check if were are master and as it's not, it just go straight to instantiating his own Player Prefab.
The error happens before the instantiation of the Prefab. And that's where I understand why. The RPC is supposed to be received from a component that's on the Player Prefab. I didn't instantiate it yet, so it can't receive it.
The fun part of course is that this error is triggered only once and that absolutely everything is working fine after the instantiation, there are no problems at all. Everything is synced etc. So you could say "ok just ignore the error and move on" But I have OCD with those red lines. It doesn't look professional in the Player Log either and I'm not accepting errors in my project, simple as that :)
More info:
The RPC is sent like this from this Character script located on the Player Prefab:
public override void OnPlayerEnteredRoom(Player player)
{
if (photonView.IsMine && gameObject.activeSelf)
{
var lcm = Locomotion;
photonView.RPC(RPC_CHARACTER, player, transform.position, lcm.canUseNavigationMesh, currentControls, new Vector2(Locomotion.runSpeed, currentAngularSpeed),
currentGravity, currentJump, (int)lcm.faceDirection, syncAttachments ? SerializeAttachments() : emptyHashtable);
}
}
The RPC is received as:
[PunRPC]
private void UpdateCharacter(Vector3 position, bool canUseNavigationMesh,
Vector2 controls, Vector2 speed, Vector2 gravity, Vector2 jump, int faceDirection, Hashtable attachments)
{
Some code
}
At that point I have no clue on how to troubleshoot this issue anymore. Do be fully transparent, I'm using a Unity module which lift the heavy weight on the Photon side and allow me to do most things in a visual scripting way. But I do know my way around code but that's also the reason why I'm not sharing too much details on code here, but can answer any questions of course!
Thank you in advance for your support, I hope my post isn't too complicated to understand
Comments
Hi @Necka,
Thank you for choosing Photon and for doing your homework fist then trying to provide as much details as possible.
What PUN version is this?
What Unity version is this?
Could you please post the exact error + stack trace without any modifications?
I'm not sure if "ERROR You have missing MonoBehaviours on your gameobjects!" this is from PUN?
What you guessed is probably right, the RPC is being received while the networked GameObject is either not instantiated, not instantiated yet or instantiated then removed.
This could be due to scene loading or a timing issue (race condition of some sort).
Hello @JohnTube
So yes, I'm sorry I forgot to indicate those important information:
Pun 2 version 2.3.0
Unity 2020.3.5 LTS
The stack trace isn't modified, I just added a few info to the error message but without modification it's:
ERROR You have missing MonoBehaviours on your gameobjects!
UnityEngine.Debug:LogError (object)
Photon.Pun.PhotonNetwork:ExecuteRpc (ExitGames.Client.Photon.Hashtable,Photon.Realtime.Player) (at Assets/____Assets/__Asset Store/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:473)
Photon.Pun.PhotonNetwork:OnEvent (ExitGames.Client.Photon.EventData) (at Assets/____Assets/__Asset Store/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2210)
Photon.Realtime.LoadBalancingClient:OnEvent (ExitGames.Client.Photon.EventData) (at Assets/____Assets/__Asset Store/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3336)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer) (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PeerBase.cs:891)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/EnetPeer.cs:558)
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PhotonPeer.cs:1837)
Photon.Pun.PhotonHandler:Dispatch () (at Assets/____Assets/__Asset Store/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:223)
Photon.Pun.PhotonHandler:FixedUpdate () (at Assets/____Assets/__Asset Store/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:149)
Yes the error message is from PUN, as you can see in PhotonNetworkPart.cs line 473
I am 100% sure that this is caused by the RPC being sent from the OnJoinedRoom() but the issue is that I saw that from multiple scripts not only from mine (like the asset: SmoothSync)
Basically let say on Player's 2 computer he arrives in this room that player 1 created.
So on Player's 2 computer, the Player 1 remote player prefab gets instantiated.
That when (I think) this remote Prefab send this RPC
But my Player 2 just arrived and has not yet instantiated its own Player Prefab so that's why it's throwing the error.
I kind of eliminated the load issue as I've just tried to do: Arrive in scene => JoinRoom("room") => do nothing. The error is triggered.
My problem is: I can't instantiate Player 2 prefab before being in the room as PhotonInstantiate() requires to be in a room (right?)
So I'm in this kind of brain loop right now where I kind of understand why it's happening but have absolutely no clue on how I could make it not happen... thus the days of troubleshooting, giving up and coming here for a clue :(
A quick update, I noticed that if I do not use:
PhotonNetwork.UseRpcMonoBehaviourCache = true
but instead use:
PhotonNetwork.UseRpcMonoBehaviourCache = false
The problem doesn't exist anymore.
I guess as the prefabs use the same component with the photonview, it gets cached when Player 1 first create the room.
I'm wondering how I could avoid this issue now in terms of logic as refreshing the cache would probably not help. Or maybe I didn't understand how this works
Hi @Necka,
Did you try keeping UseRpcMonoBehaviourCache to true but call "Refresh RPCs" in PhotonServerSettings under "RPCs"?
LaPanthera
2023-03-05 19:20:03
I had same issue and the matter was that in my network prefab i had missed scripts.
Back to top