Multiplayer authority not being set correctly

Godot Version

4.2.1

Question

Hello!

I followed this famous tutorial over the weekend - https://www.youtube.com/watch?v=n8D3vEx7NAE&t=1646s&ab_channel=DevLogLogan

I am having trouble with multiplayer authority. I’ll attach my code but long story short when i call

set_multiplayer_authority(str(name).to_int())

when clicking join, to join the host player the authority is not set properly. If i print name and get_multiplayer_authority() the values are identical but if I print is_multiplayer_authority() I get false.

I’ve checked my code 100 times compared to the tutorials repo and as far as the world scene which handles the hosting and joining along with the setting authority in the enter_tree() function they are identical. I’ve added some other changes but can’t see how they’d effect the networking side.

I’ve created a repo so you can see my two scripts which handle the networking/player joining.

I’ve googled for almost 2 days trying to find the answer and can’t find many results. As I say I’ve added some things to the player like the subview port container which contains a weapon manager and stuff for the player first person view but can’t see how that would effect the multiplayer authority. I can upload this code if you think it’s pertinent.

Any help would be greatly appreciated. Thanks!

Do you get any errors regarding authority?

I think I set my authority after ready function. By using call_deferred set multiplayer authority.

Anyways after you set authority, are you sure you are looking at the right instance of the game? I.e. looking at the host version of the client node?

That is_multiplayer_authority will by false on the server instance. You can call multiplayer.get_unique_id() to check who you are when that code is running.

no errors, i just know it’s not working because in the ready function in the player script I have this

if !is_multiplayer_authority(): return
    camera.set_current = true

on the second client the camera is never set to current.

Okay, I’m not sure then. Try moving the authority set to the ready function with a call_defered("set_multiplayer_authority",id)

this is what I do and it doesn’t give me any issues.

In the early stages of Godot 4 it had a lot of issues with auth setting. And that video is pretty old.

You don’t need to change much except on the _ready function switch to if not name.to_int() == multiplayer.get_unique_id(): ...

1 Like

Ok thanks, i’ve tried that and I get the same result.

While the game is running I go into the editor and look at the remote tree. I can see both players there and in the inspector they have their separate Multiplayer Authority ID’s correct yet the ready function doesn’t run past the if statement.

func _ready():	
	call_deferred("set_multiplayer_authority", name.to_int())
	if not name.to_int() == multiplayer.get_unique_id(): return
	characterModel.visible = false
	subViewPort = subViewPortScene.instantiate()
	camera.add_child(subViewPort)
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	camera.camera.current = true

I feel like i’m going crazy! haha

Untitled

This could be tricky, but there are two instances of the game running and 4 player nodes total. Two on server side, two on client side

If we look at the client player node.name “123456”:

Server is authority returns false. Client side returns true.

If we look at server side player node.name “1”:

Server is authority returns true, client side returns false.

When running multiple instances there are different output tabs for each game instance.

I want to be clear that we are looking at the right instance. There is no indication on which window is running server and client. It can make it easier to isolate output if you run the server from command line. And run the client in the editor. You can then debug more easily what is going on.

To be clear I don’t see anything wrong logically with what you are doing even in the original version. We may be focusing on the wrong thing.

Ok great idea. So i duplicated the project and ran it separately in two separate editors.

It seems that when I click join on the second client the add_player() function which instantiates the player doesn’t run on the client side. The host registers the player joining and creates the player object but nothing happens on the client side…

I get these in the debugger but googling doesn’t show up much

E 0:00:02:0376 get_node: Node not found: “World/1/MultiplayerSynchronizer” (relative to “/root”).
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1638 @ get_node()

E 0:00:02:0376 process_simplify_path: Parameter “node” is null.
<C++ Source> modules/multiplayer/scene_cache_interface.cpp:76 @ process_simplify_path()

Do you use a multipleplayerspawner And are you adding child to the spawners watched node?

yes i have a spawner and each player has a synchroniser attached. I’ve uploaded my full project here GitHub - shaunzorr/godot4_mp_help

hopefully theres something obvious you might be able to spot

When I look at the scene options for the spawner I don’t see player as a spawnable scene, only the spawn path.

that fixed it, thank you very very much! let me know if there is any way I can thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.