I didn't notice until now but Hosts camera can not be controlled when launched

I have no clue why this is happening, I finished this lecture, went to test, and realized whoever was hosting was not able to move their camera. I went back to a previous commit (the end of the last lecture) and it looks like it was happening there too. and the camera isn’t starting where the player spawn is any more, I have no idea what’s going on. I’m so frustrated because it was going great up until this point and now I have no clue where to begin to fix it. I really don’t want to have to go back several commits and redo these lectures, but I guess that’s what I might have to do. I don’t know. Any help would be appreciated.

And if it’s helpful at all, I’m not receiving any errors. It just looks like the camera on the host side starts in the middle and moves up and left then stops at the edge of the terrain.

Hi there,
Happy to help you figure this out. The first place I would is the camera controller script. Add some debug statements and see if the UpdateCameraPosition method is getting called correctly.

My first goal would to see if the method is being called correctly, then see if all the references are correct, and the input is being read correctly from the mouse.

okay awesome! so I went ahead and went back to the commit prior to beginning the Menu UI lectures, and can confirm it was working correctly before. I just went back through the lectures for making the UI and the scripts for it (the previous two lectures) and at the end of the last lecture the camera is doing the same thing again.

I am gonna go ahead and throw in some Debug.Logs in the camera controller script and I’ll come back here with any information I gain from that.

Thank you!

1 Like

Okay so I did find something interesting with the logs.

I logged out position of the player camera, and it appears the camera position is moving but the main camera I guess isn’t recognizing that camera for the host or something. Like I can see the playerCameraTransform.position is changing when I use the WASD keys to move it, and they are changing as would be expected. So somewhere in the making of the scripts from the last lecture the main camera stopped behaving correctly for the Host. It’s really weird, the camera starts in the middle for the host, then moves by itself to the top left area, where the first player spawn would be, then is unable to be controlled.

it does mostly work correctly for the non-host player, but the camera doesn’t start at their starting position, it starts in the middle.

I’m going to try going back through this lecture now because I know at the end of the last one a lot of things were broken, and this lecture is supposed to address that. I’ll see how it behaves at the end of this one this time.

Okay, just finished this lecture and still having the same issue. The player that is not the host that joins is able to control their camera correctly, but it starts in the middle of the map vs. at their starting position, and the Host player can not control their camera at all. I can see in scene view though (hosting on the Unity side not the Build side) that when I press the movement keys, the player camera is moving in the scene view, and not on the game. So for some reason the player camera doesn’t seem to be taking over the main camera. I opened up the player objects in DontDestroyOnLoad in the hierarchy and I see that the non-host players camera is Live but the Host players camera says Standby.

Are you testing it with the host in a build and the player in the editor or vice versa? Does it make a difference which player is in the editor/build?

Can you show the set up in the inspector and hierarchy in the editor?

This could be an issue of another Camera in the screen taking priority over the player camera. Are there other cameras in your scene?

sorry for the delay in getting back. Yes I’ve tried hosting on both ends and the issue happens on both. There is the main camera with the cinemachine brain in the map scene, but it was my understanding that was supposed to be there, maybe I have it in the wrong place? It does seem like the hosts camera goes to the main camera and doesn’t switch from it. it’s really weird

here’s a picture of my hierarchy if it’s helpful at all

Looking at my own project, I can see that the Player Camera is disabled in the prefab. Then we activate it on OnStartAuthority. Is yours also disabled in the prefab? The act of activating it might be what gives it precedence over the main camera.

Otherwise make sure the MainCamera has priority of -1 and the player camera has a higher priority.

Mine is not disabled in the prefab, I don’t believe it was ever said to do so in the course, but I will try it. You enable it in OnStartAuthority in the RTSPlayer script, or which file? And by enable do you mean you do a SetActive(true) or just disable a component on the Camera object and do camera.enabled = true?

It’s enabled in the camera controller I believe.

ooooh okay, i see it. let me try messing with that

Wellp, that seems to have fixed the issue more or less, it seems like the player objects are still spawning in the middle vs. where their spawn point for their bases are, but maybe I can find what’s causing it to do that now. Thank you for helping me! If you have any thoughts as to why the camera / player prefab doesn’t seem to be spawning in the right place, that would be great! It worked before I did the Menu UI part of the course.

I would just add some code to that OnStartAuthority in the Camera Controller to reposition of the camera. I think what I did, was find the player base position, then offset the camera by a fixed amount so that it was looking at the base. (If you put it directly over the base, you won’t be able to see anything.)

Something like cameraTransform.position = playerBaseTransform.position - Vector3.forward * offset;

okay yeah that sounds like a good idea! how should I get the base position for the specific player from the CameraController script? I was adding in a public Vector3 variable to the RTSNetworkManager script, and updating it in the OnServerSceneChanged function where it instantiates the baseInstance for the player, but I wasn’t sure if that was going to work because I’m not sure that I was specifying that it needed to be the specific player

We store a list of buildings on the RTSPlayer object, you can check that for the base.

i might need you to give me a specific example. I see we have the private serialized field which is an array of Building objects called buildings, then we have a List of buildings called myBuildings, which we made a getter for. I’ve tried iterating through the list but I’m pretty sure that list only gets added to when a building is placed, and I don’t think the base is part of it. Should I make a getter for the buildings array and get it that way?

Also, putting in some Debug.Logs, the code in the OnStartAuthority in CamerController runs before the bases are instantiated in the RTSNetworkManager, and the position of the building in the buildings array is 0, 0, 0. So, I guess the camera transform needs to be changed after the buildings are set right? Unless I use the spawn point positions?

sorry I don’t mean to be annoying but this is literally the only thing keeping me from finishing this course

okay so after checking some logs I’m noticing that the players bases are not being spawned at what is supposed to be their starting positions, it’s like, one off. like, when I log GetStartPosition().position in the RTSNetworkManager script for the first player, I get 39, 1.5, 44 (which is one of the spawn points). But their base is being spawned at -40, 1.5, -36 (which is another one of the spawn points). So I’m trying to move the camera to their start positions but the bases aren’t being spawned at the start positions lmao. I don’t understand how this got so messed up just introducing the lobby ui

okay so I pretty much got it to work.

What I ended up doing was in the RTSNetworkManager script, after the NetworkServer.Spawn() function I updated the position of the Player prefab (which contains the camera already set to an offset from the parent object) to the position of the baseInstance. I had to add a bit to the X axis (or subtract a bit, depending on whether the float was positive or negative in the x of the base position) and that pretty much gives the same behavior as it originally had before everything started acting crazy lol.

Thank you for all your help! I don’t think I would have reached this resolution otherwise. I definitely never would have found the camera not being set to active in the player prefab lmao.

1 Like

Privacy & Terms