Starter Assets Third Person Controller and Netcode for GameObjects

I wasn’t sure where to post this. I could have put it in Cinemachine or Input System or here and figured this was most appropriate.

I am making a multiplayer game using NGO and the Starter Assets Third Person Controller.

I am using Unity 2021.3 and the latest release versions of NGO. No beta stuff.

I put the NetworkObject on the parent of the “system” that the 3rd person controller prefab includes. The children include a cinemachine system and the whole thing uses the “new” unity input system.

When I start the Mac app I built and start the Host and walk around everything works as it should. I can walk around and the cinemachine camera follows like it should.

I am using the github ClientNetworkTransform because I am fine with client auth for movement.

I also created my own OwnerNetworkAnimation so I could get the client auth for animation according to the documentation on the Unity website.

When I then start the editor and connect as a client, the cinemachine camera in the app that is running looks like it switches to the client that just spawned in. If I shutdown the client then cinemachine goes back to the host avitar.

Along with that the Host player that spawns in to the game running in the editor spawns in the same spot as the client. The initial position isn’t updated. As soon as I move the player in the Host app, the player does move in the editor app.

When I try to move the player in the editor (client), the animation plays on the HOST player avatar. It doesn’t move, but the animation plays. This seems to tell me that the input manager is sending stuff to the wrong avatar or the wront avatar is listening or something like that.

As a second issue, even though I have the client auth component, when I try to move in the client the animation plays, but it doesn’t move.

A third issue is that animations are not syncing at all.

I could really use some help to get this to work.

I ported the Starter Assets character controller to netcode but using my own movement code (quake style), you can check it out here: UnityNetcodeBiteSizeExamples/Assets/Plugins/CodeSmile/Netcode/QuickStart/05_CharacterController at main · CodeSmile-0000011110110111/UnityNetcodeBiteSizeExamples · GitHub

It also works server authoritative but that is more of a proof of concept and needs a lot more work to make it smooth on client side.

Thank you! I will give this a try.

I am having trouble opening your project. I get the following error:

Not sure why you have a direct reference to your hard drive in the packages file.

I also tried just making my own project and copying just the Third Person folder to it and it gives errors about duplicate methods in the thirdpersoncontroller script because i also have the third person asset in my project.

Without the unity assets in my project, however, I get errors that there are missing scripts.

I really appreciate your helping, but would like some instruction on how to use what you have created…

Hey @Hotshot10101 , you can fix the reference to the package by opening your project’s folder and going into Packages > manifest.json . There you should be able to specify the version of @CodeSmile 's package instead of a local path.

I’m not a user of such package, but from what I see here one of the live versions should be 0.1.0, so you should be able to specify

"com.codesmile.core": "0.1.0", in your manifest file.

Does this help?

@Hotshot10101 I found CodeSmile’s package on its public github, it’s here. You should be able to reference the latest commit ( 5ec2764d89b8757c6ad20e1ec7bbf4083f5ea561 ) from the develop branch of its repo by adding to your manifest:

"com.codesmile.core": "https://github.com/CodeSmile-0000011110110111/CodeSmile-Package.git#5ec2764d89b8757c6ad20e1ec7bbf4083f5ea561",

Looks like there is another package called com.codesmile.metal which I can’t find.

I opened an issue on their github:

Hey [mention|qqVrV9kb3cSKWzllUEyJ1Q==] , I have an update for you: maybe you’re experiencing a similar issue to the one mentioned in this thread . Maybe some of the concepts explained there would apply to you?

I just modified the ThirdPersonController that comes with the standard assets to make it usable in a multiplayer environment. Basically all I did was:

  • Make it a NetworkBehaviour
  • Add if (!IsOwner) { return; } at the beginning of the Update() to ensure only the inputs from the local owner are sent

Your timing is great. I was just thinking about this last night when I was going over a tutorial video. I suspect you are right.

Thanks for confirming that is probably it!

1 Like

How did you deal with the fact that the NetworkBehaviour requires a NetworkObject on the same GameObject?

The reason this is an issue is because in order to have a single GameObject to put on the NetworkManager, I created an empty GameObject and put the entire Third Person stuff under that. This includes the PlayerAmature, PlayerFollowCamera, etc.

Without all those things it doesn’t seem to work.

I had to put the NetworkObject on that parent game object and then drag that onto the NetworkManager as the player spawn.

That means I can’t put the NetworkObject onto the PlayerAmature and it keeps complaining that a NetworkBehaviour needs a NetworkObject with it.

The host side does seem to work now including the animations, but the camera isn’t following and the client side isn’t working, so still looking into those.

I didn’t: i’m using the PlayerArmature as the parent object, so all the scripts are on it (including NetworkObject). Is it something you could do too?

You should set the target of the camera as the local player, and ensure other players don’t have a camera at all (I.E: by removing it from the prefab and instantiating + assigning it in the OnNetworkSpawn of a NetworkBehaviour of the Player, or by keeping it disabled and enabling it for the local player only using OnNetworkSpawn)

I ended up doing something like this.

I made the PlayerArmature the player object that will get instantiated and then put a single copy of the rest of the stuff in the scene.

I then had to modify several of the scripts to use the IsOwner to only do a lot of the functionality in that case.

This seems to work.

thanks for all the help and tips.

1 Like

That’s definitely not enough. The host will work just fine that way but the client won’t be able to move (using NetworkTransform and not ClientNetworkTransform). I understand the movement has to happen on the server through a serverRPC but it’s just confusing enough that I can’t figure it out on my own. I’d really appreciate your help.
EDIT: I was so close but couldn’t figure out what I was doing wrong. Then I found this video and everything I needed was in there:

3 Likes

Thank You!

The video seems to be blocked. Is there a way for you to make the link visible?

The video is great but for some reason the input animation mapping is messed up when you go backwards.

There’s a slight difference with the Cinemachine camera that you need to be aware of. In the video he sets the camera to follow the transform of the GameObject. The starter asset uses a child transform for the follow. It’s called PlayerCameraRoot and you set this in the inspector on the PlayerController as the Cinemachine camera target. To set this programmatically, replace the code you will have copied from the video above with this:

public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();

if(IsClient && IsOwner){
_playerInput = GetComponent<PlayerInput>();
_playerInput.enabled = true;
// _cinemachineVirtualCamera.Follow = transform;
if(CinemachineCameraTarget != null){
_cinemachineVirtualCamera.Follow = CinemachineCameraTarget.transform;
}else{
_cinemachineVirtualCamera.Follow = transform;
}
}
}
1 Like

how can i turn it to NetworkBehaviour, actually my code doesn’t work with unity.netcode;
I think maybe it in packages and netcode in other folder.

help me please