#archived-networking
1 messages · Page 32 of 1
If you are using NGO2 then you no longer need that one. There is a drop-down variable for authority type on the Network Transform.
The webinars should all be listed in #📢┃announcements
I had a question regarding Netcode's .Spawn method. I was wondering if .Spawn recreates a copy of the object it is used on or the object's prefab? An example of why I need to know would be a dash special effect that leaves afterimages of the player. The prefab's sprite renderer starts off null, but is dynamically set to the player's current sprite. If I were to spawn the object, dynamically set the afterimage sprite, then call .Spawn, would the client side afterimage's sprite renderer be null or would it be the same sprite saved in the object?
It would be null. It replicates on clients based on the prefab.
You would need to set the sprite in that new objects OnNetworkSpawn()
If I was using an object pooling system and the method SpawnFromPool. Would I want to call .Spawn in SpawnFromPool or whatever code is calling SpawnFromPool? A problem I thought of was that if we call .Spawn in SpawnFromPool, but we need to change certain values of the spawned object after spawning, we wouldn't be able to use OnNetworkSpawn right?
If you are using Network Object Pooling then you can use NetworkObject.Spawn() as normal. OnNetworkSpawn() still gets spawned
Netcode for GameObjects (Netcode) provides built-in support for Object Pooling, which allows you to override the default Netcode destroy and spawn handlers with your own logic. This allows you to store destroyed network objects in a pool to reuse later. This is useful for often used objects, such as projectiles, and is a way to increase the app...
Oh alright, thank you so much!
I assume it would be the anticipated network transform?
No, just the regular Network Transform.
I dont seem to have any drop-down variable for the Network Transform for Client only
Only got :
In Local Space
Interpolate
Slerp Position
Use Quaternion Synchroni
Use Half Float Precision
What version are you on?
2022.3.46f1
oh this is only in NGO 2.0+ for Unity 6
Oh shoot
that explains it
but then i wouldn't have problems with installing the Client Side Network Transform tho?
I don't know if NGO 1.11 or 1.12 has it though
@vivid zodiac it's a really simple script, you can just create it yourself.
using Unity.Netcode.Components;
using UnityEngine;
namespace Unity.Multiplayer.Samples.Utilities.ClientAuthority
{
/// <summary>
/// Used for syncing a transform with client side changes. This includes host. Pure server as owner isn't supported by this. Please use NetworkTransform
/// for transforms that'll always be owned by the server.
/// </summary>
[DisallowMultipleComponent]
public class ClientNetworkTransform : NetworkTransform
{
/// <summary>
/// Used to determine who can write to this transform. Owner client only.
/// This imposes state to the server. This is putting trust on your clients. Make sure no security-sensitive features use this transform.
/// </summary>
protected override bool OnIsServerAuthoritative()
{
return false;
}
}
}
I'll take a look, thank you :))
That's literally just the whole script?
Yeah.
Anyone here familiar with steamworks and can explain to me the difference between a CallResult and Callback? I understand how delegates and events work in regular C#. I don't understand the difference between these two types
is there any other samples for the ReadDelta and WriteDelta of the custom NetworkVariable? I hope they can just include it in the docs instead of just saying // Do nothing for this example.
you can send an RPC with a NetworkObjectReference
how should I send an rpc to a specific client? I looked at the docs and there are examples using ClientRpc but apparently its deprecated
ah okay it looks like RpcTarget.Single((ulong)clientId, RpcTargetUse.Temp) something like this
I don't know what RpcTargetUse really is though
the docs aren't very helpful
it is documented, but not in the most obvious place
Its used to help with garbage collection. You would use persistent if you have a group you are always sending to like Teammates
when you say "always" do you mean like constantly?
Not necessarily. Its just for like caching the group so you don't recreate it every time you call the RPC
your example uses clientRpcParams, which I was under the impression is only able to be passed into a ClientRpc, which is deprecated now
like this
Legacy - not deprecated.
sorry yes, legacy
it's just netcode for gameobjects
I figured out how to do what I want (i think) so dont need to worry about me
I tried googling how to make a gameobject be client authoritative, and this old out-of-date documentation page is what showed up
does anybody know the current way I should do this?
Here are the docs for ClientNetworkTransform. But if you are using the latest version of NGO2 then you can set the authority directly in the Network Transform
Introduction
yes. For Network Variables, you can set the write permissions to owner
NetworkVariables are a way of synchronizing properties between servers and clients in a persistent manner, unlike RPCs and custom messages, which are one-off, point-in-time communications that aren't shared with any clients not connected at the time of sending. NetworkVariables are session-mode agnostic and can be used with either a client-serve...
so instead of a gameobject being client authority in general, I would need to make network variables in my networkbehavior script and work off of those?
yes. you can mix permissions on the same object if you want
is there a way to get the owning client id from a player gameobject?
or should I cache the client id at the start of runtime
You can get it from any NetworkObject
Caching is never a bad idea however
Hey,
I'm getting an issue with multiplayer playmode, but not sure if it's auth related or multiplayer play mode related.
I'm using Unity6 (6000.0.26f1) and multiplayer services 1.0.2
Running platform profile (Default Windows)
And when I activate Player2 I have a logic that initializes unity services then signs in anonymously
(I initialize unity services using default ctor without init options)
When I try it out in the main editor it's fine, but on the 2nd editor (Player002) it throws an error exactly when I try to sign in anonymously
Saying
Unity.Services.Authentication.AuthenticationException: invalid environment name provided ---> Unity.Services.Authentication.WebRequestException: {"detail":"invalid environment name provided","details":[],"status":400,"title":"INVALID_PARAMETERS"}
Am I asking this in the right place?
NOTE:
I also get the same error in default editor when I switch to "built profiles" but when choosing the default profiles everything is fine.
I believe you need to switch authentication profiles when signing in anonymously on the same machine. Not why it's giving an environment name error though. Make sure services settings have the correct environment name.
if I call Despawn on a gameobject (server authority), does that mean Update() will stop being called for it?
In the editor I'm choosing the Environment from the Project Settings to be "dev"
It works on my main editor, but it throws the env error on the Player002 clone-editor
I would think so, as it would destroy this gameobject's instance in the network.
Oh wait, you said Despawn not destroy
I mean like does it happen immediately - is there a guarantee that the next tick Update() won't be called for a networkobject that I called despawn on last tick
Hmm good question,
Maybe worth doing a test in your client and server Update method
Keep firing logs and also fire a log when it's destroyed/despawned
You'd be able to see if a log in Update gets fired after despawn
Despawn(false) will keep the object around on the server. The default is Despawn(true) which will destroy the network object.
There is also a DeferDespawn() that will delay it by a certain number of ticks
thanks, makes sense
One more thing - on a network behaviour script, who is allowed to modify variables? I mean ones that aren’t explicitly declared NetworkVariables
And is the prefab for a player that is specified in the network manager a special case or the same as any other network behaviour script
far as I can tell it's server authority for these
in which case, is this only working because I have a NetworkTransform component with client auth mode?
Default write permissions is Server
That is correct
I have a NetworkObject that starts in the scene and I want to cache a reference to one of it's components in my player's NetworkBehaviour script.
I think this works? tested and no crashes or unexpected behavior
at a high level I want items (like dropped stuff in minecraft) be able to interact with the correct inventory of a player thats nearby
Change Start() to OnNetworkSpawn() and it will be good
What could go wrong with using start
Start() gets called before the object spawns. So clients will get an error when the RPC gets called
If you haven't already read the Using NetworkSceneManager section, it's highly recommended to do so before proceeding.
also IsOwner is not properly set there either
thanks
one last thing - I feel like I don't super understand how it works when there's a host
it's a client that is also the server
meaning - if I write in my player script code that modifies variables (without a server rpc), it'll actually make the changes, but only in the host instance? other client instances will also try to run the code locally but it won't actually change variables?
from a NGO perspective that's basically it, it's a player that counts as both for the purposes of ownership and RPCs, the rest of the logic is kind of up to you to implement
a lot of the time you want to be checking IsOwner in Update etc so clients only update their own objects and the host doens't try to update other clients' objects
Normally, you would check if IsHost/IsServer/IsOwner before making any changes to Network Variables
yeah - I mean for like regular variables (in a networkbehaviour)
I feel like i didnt explain what i meant very well
regular variables are always local and will never get replicated to other clients/the server
lets say i have a networkbehaviour script on a networkobject and it has a variable public int x = 0, and then inside Update() I do something like x = 5;
dang im confusing myself
but essentially for clients the modification will be ignored by the server right?
because it's server write perms only
i'd have to do rpc server call from client to request the server modify x, or make x a NetworkVariable<int>
x is not a network variable there. all clients and the server would be able to change their local x variable independently
makes sense - and for the host, it only has one copy of x between its client and server?
Yea. the host is a single entity. It just runs as a server and client at the same time.
I see now.. in this code I'm just changing the host's local variables. Other clients don't actually have updated local versions, which I imagine will lead to unexpected behaviors (if im not careful)
Just keep in mind that there are only 3 ways to send data in NGO. Network Variables, RPCs, and Custom Messages
would it be better to have a NetworkVariable that holds a reference somehow?
I know it's not possible to do NetworkVariable<MyCustomComponent>
is it allowed to do NetworkVariable<NetworkObjectReference>
sure there is also NetworkBehaviourReference
Brief explanation on using NetworkObject and NetworkBehaviour in Network for GameObjects
oh thats awesome, that's probably the way i want to do it
I tried to refactor but I'm running into this problem
I can't any examples in the documents where they use a NetworkObjectReference or NetworkBehaviourReference as the type for a NetworkVariable
Is your InventoryManager a Network Behavior on a Network Object?
Could still be a timing issue. try using OnNetworkPostSpawn() to make sure all objects have spawned
it's still complaining
it has to do with FindFirstObjectByType<InventoryManager>()? that's the line that is causing the exception
if i have interpolate turned on on networktransform should rigidbody component interpolate be off?
That shouldn't matter as long as the InventoryManager object has been spawned. You could that it's .IsSpawned is true before sending it in the RPC.
I don't think it matters either way.
ah you're right, it's not spawned yet
I guess it makes sense that networkobjects in the scene are also waiting to be spawned when I start host
how do I delay trying to set it until the object is spawned?
I am using the OnNetworkPostSpawn() function too
okay, I figured out a solution. not sure if its best practices but whatever
I basically check if the inventory is spawned yet. if it's not, then subscribe to an action delegate from inventory script that gets invoked when its networkobject is spawned
if it is already spawned, then just add it
for some reason, the host seems to always spawn the player first, and a client spawns the inventory manager first
not sure how unity works!
there is any tutorial how to use unity3d 6 multiplayer center? Some examples how start with that (not just sample gameobject and scenes cuz only that i found), I focus on server hosted method :#
The Quickstart Sample scenes are why you use the Multiplayer Center. You can use the widgets separately if you want them in your own scene
Is there any method like "OnSceneChange" for the NGO so when the scene changes i can get my custom network manager to check the name of that scene and if it matches just do what has to be done, i could very well put it in Update but it's not worth checking the scene name every frame
If you haven't already read the Using NetworkSceneManager section, it's highly recommended to do so before proceeding.
Thank you 
does netcode for entities support adding component at runtime? I read the documents are it seems like it, but I am not sure if I understand it correctly since adding component at runtime sounds like a feature that too important to be ignored
none of the networking solutions for unity support that
Technically you can make it work. You probably shouldn't though. Structural changes in dots will tank performance. Components added at runtime won't be synced so you'll have to manually update them with RPCs
The folks on #1062393052863414313 would have more insight on this
public void SpawnUnitServerRpc(ServerRpcParams rpcParams = default)
{
// Instantiate and spawn the unit at random position
Vector3 spawnPosition = new Vector3(Random.Range(-5f, 5f), 0, Random.Range(-5f, 5f));
GameObject unit = Instantiate(unitPrefab, spawnPosition, Quaternion.identity);
var instantiatedUnit = unit.GetComponent<NetworkObject>();
instantiatedUnit.SpawnWithOwnership(OwnerClientId);
// Add unit ID to GameManager's NetworkList
GameManager.instance.AddUnitServerRpc(instantiatedUnit.NetworkObjectId);
}
Hello. I am having a little difficulty working on the logic for something I want to do. Above is the code I have but I don't think it does what I want.
I want to look at the unitPrefab on the PLAYER and instantiate that prefab. The instantiated unit should have all of the customization, abilities and choices that the player chose before the match started. I understand i will need to instantiate (or call an index#) for each of those customizations. What I dont get is, if the SERVER is calling this RPC, isnt the thing being spawned just the default prefab without the player's choices on it?
That is correct. You would need to send those customizations to the server in the RPC parameters. Or you could have those as Network Variables on the default prefab and let the client update them after they spawn
If i go the NetworkVariable route, how would I, for instance, instantiate a hat on the unit?
Depends on how many you have. They can all be on the prefab and just disabled. Or you could instantiate them locally on each when the network variable is updated. If they are network objects for some reason, they will have to be spawned separately then reparented to the player
So the eaier way is to make the gear/clothes just be there to begin with it looks like. This is incredibly helpful thank you.
Can someone help me to figure it out what am i doing wrong, when i`m Loading scene my host have an error that he has 2 audiolisteners, also client is controlling my host
The audio listeners is probably from having two cameras active and the client controlling the host means you're not making the correct checks on player input
Can someone tell me why my host moves just fine but my client has slow jittery movement?
using UnityEngine;
using UnityEngine.InputSystem;
using Unity.Netcode;
public class PlayerMovementController : NetworkBehaviour
{
[SerializeField] private float moveSpeed = 5f;
[SerializeField] private float rotationSpeed = 720f; // Speed for rotating to face movement direction
[SerializeField] private VariableJoystick virtualJoystick; // Reference to the joystick
private PlayerInputActions controls;
private Vector2 moveInput;
private void Awake()
{
controls = new PlayerInputActions();
controls.Player.Move.performed += ctx => moveInput = ctx.ReadValue<Vector2>();
controls.Player.Move.canceled += ctx => moveInput = Vector2.zero;
}
private void OnEnable()
{
controls.Enable();
virtualJoystick = FindAnyObjectByType<VariableJoystick>();
}
private void OnDisable()
{
controls.Disable();
}
private void Update()
{
if (!IsOwner) return; // Ensure only the owning client can control movement
Vector2 joystickInput = virtualJoystick.Direction; // Get joystick input
Vector2 finalInput = moveInput + joystickInput; // Combine inputs
MovePlayer(finalInput);
RotatePlayer(finalInput);
}
private void MovePlayer(Vector2 input)
{
Vector3 move = new Vector3(input.x, 0, input.y) * (moveSpeed * Time.deltaTime);
transform.Translate(move, Space.World);
// Synchronize movement across the network
MovePlayerServerRpc(transform.position);
}
private void RotatePlayer(Vector2 input)
{
if (input.sqrMagnitude > 0.01f) // Check if there's movement input
{
// Calculate the direction to face
Vector3 targetDirection = new Vector3(input.x, 0, input.y);
Quaternion targetRotation = Quaternion.LookRotation(targetDirection);
// Smoothly rotate to face the target direction
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
// Synchronize rotation across the network
RotatePlayerServerRpc(transform.rotation);
}
}
[ServerRpc]
private void MovePlayerServerRpc(Vector3 position)
{
MovePlayerClientRpc(position);
}
[ClientRpc]
private void MovePlayerClientRpc(Vector3 position)
{
if (IsOwner) return; // Skip for the owner to avoid redundant updates
transform.position = position;
}
[ServerRpc]
private void RotatePlayerServerRpc(Quaternion rotation)
{
RotatePlayerClientRpc(rotation);
}
[ClientRpc]
private void RotatePlayerClientRpc(Quaternion rotation)
{
if (IsOwner) return; // Skip for the owner to avoid redundant updates
transform.rotation = rotation;
}
}
You’re just sending raw positional data back and forth across the network, which is subject to latency and jitter. I would recommend using the NetworkTransform component
I fixed it , forgot to remove my question
I changed authority mode on the player prefabs network transform from server to owner.
Now host and client move properly
If you are using Network Transform then be sure to remove those RPCs.
Remove the server RPC's?
The network transform itself is already syncing position and rotation. Your RPCs there are redundant and a waste of bandwidth
oh yeah I forgot about that
I took a year off c# and jumped into python , trying to re-review and get back into networking altogether
How do I fix "Internal build system error. read the full binlog without getting a BuildFinishedMessage, while the backend process is still running"?
in my experience it's usually it's just a unity hiccup or antivirus or something interfering with the build, and reimporting a script or making a code change will make it go away
hi guys im having trouble setting permissions on a NetworkVariable, does anyone have an example, im trying to sync a vector3
reverted to my old code that works but im trying to sync 2 mouse pointers only one of them works
or itself someone has some any good solution for spawning for example Tree thru static methods like some system soo I dont need to access like list of all networked prefabs but just do Like SpawnableObject.Spawn(ObjectType.Tree) which will return NetworkObject
I think anyway I need to create own scriptable object for this
does a networktransform really od all the work without needing rpc?
been trying to sync to mouse pointers but spent along time with no success lol
one works the other just randomly jumps around
You can access the network prefab list. NetworkManager.NetworkConfig.Prefabs.Prefabs[]
Yes, make it owner authority and have it follow the mouse position of the local client. You spawn one mouse object for each player
thanks!, would be awesome but i cant get it to work
does it work with a child being the network transform, and its a rect transform
Has anyone tried Photon Quantum before? I heard that it is also ECS, and can write code just like a local game.Without cost consideration, would you guys recommend using DOTS+Netcode for entities, or using Photon Quantum?
For an autochess-like game
seems like dots would be overkill
The child would need to have a network transform. The parent needs to be a spawned network object
yeh i think my problem was i was tryin to make a cross hair which needs a canvas
If you game will already be using Dots, then I would recommend NFE. Otherwise I would stick with a gameobject based solution
Networking is never easy
yeh
im a network programmer lol
barely even connects have to keep restarting unity
But that said a 2d network object on a canvas will work
yeh almost had it earlier but one was jumping around
may be unity bug
unity6*
oh seems to work after restarting!
so unreliable tho, nearly always wont connect
thanks man.
How many CCU does it support for each CPU core (assuming using the Unity Multiplay Hosting)? Supposed I am using netcode for entities, and a autochess-like game, where all entities in the match will be ghost, including bullets,etc.
yeh i have to restart unity every single time to get one connect lol
works perfectly if i do that though 😄
I'm not too familiar with auto chess, but there is no hard limit. Most realtime games cap out at around 100 or so players. Turn based games can have much higher player counts.
What errors are you getting?
i dont see any
Increase the log level in the Network Manager
suddenly seems more reliable
ah good thinking
hmm just says [Netcode] [Host-Side] Transport connection established with pending Client-1.
but i never see this when it fails-> [Netcode] [Server-Side] Pending Client-1 connection approved!
Are you using Connection Approval? Are there any messages on the client side?
What does this error mean?
I have a pizza level (picrel 2) with the following hierarchy (picrel 3) with a network object on a pizza prefab. Am I doing something wrong?
Photon Quantum is production-ready
Netcode For Entities is not
Photon Quantum is infinitely better than anything Unity has ever made
I figured out what the problem is. The thing is I simply want to enable gravity when a player stand on an object, however I don't know how to solve it simply.
Seems, like I would need to spawn all these prefabs to make it work
anyone know a quick and easy way to implement a lobby
its possible to access ip address while doing approval check? also its any main reason why "Reason" in response is as string? unity ngo
anyoneseen this error KeyNotFoundException: Specified number of players (2) not found in Remote Config player options.
trying the unity serverless lobby demo
You can not. unless you send it through Connection Data for some reason. "Reason" is a string because you can enter whatever reason you want
damn why does nothing ever work without a fight with unity
looks like a very cool sample though, does A LOT of the hardwork
that sample is a bit over engineered for my tastes.
If you are using Unity 6, look into the new Multiplayer Services and Widgets packages. Using Sessions does a lot of the integrations for you
cheers, will check it out!
ah id not deployed the remote config, theres tons of new stuff in unity6 i have never seen
huh
Even though I already asked a similar question, how do I use unity as a webhost?
You don't? You would probably run a webserver along side the unity executable on whatever server machine you have access to
Hi! I have a question, im wondering for why this scene event isn't working? I just wanna say that i am pretty new to networking but gotta start somewhere, so if there is some very easy and obvious answer to why it isn't working then sorry for bothering lol, but been trying to debug it for the whole day, even asked chat gpt and still no answers.
void Start()
{
if (NetworkManager.Singleton != null && NetworkManager.Singleton.SceneManager != null)
{
NetworkManager.Singleton.SceneManager.OnSceneEvent += OnSceneChange;
}
}
private void OnDisable()
{
if (NetworkManager.Singleton != null)
{
NetworkManager.Singleton.SceneManager.OnSceneEvent -= OnSceneChange;
}
}
private void OnSceneChange(SceneEvent sceneEvent)
{
Debug.Log("Working1");
if (NetworkManager.Singleton != null && NetworkManager.Singleton.SceneManager != null)
{
if (sceneEvent.Scene.name == RoundSceneName)
{
Debug.Log("Working2");
}
}
}
Is this script in the Round Scene or in the scene before it? SceneManager might be Null is Start() since the network as not started then
Hi so I am currently changing my single player game to multiplayer. I am testing the features by running a playtest and build on the same machine. This means that I should pretty much have 0 latency between the host and the client, but I was wondering is it normal to have very slight latency when doing this? When performing a high speed action such as dashing, I noticed there is a very slight delay between the client and the host. Additionally, there is also a very slight delay when spawning objects and stuff. Is a very slight delay normal when testing on the same machine or is there something wrong?
If you are testing on Relay there will still be the usual ping delay. But even connecting directly on the same machine there will be a delay of at least a frame or two for RPCs and 1 Tick for network variable updates.
Hi, is anyone aware if it's possible to create custom inherited RpcAttributes?
I'd like to have defined attributes for common usage patterns, eg [FXRpc] instead of [Rpc(SendTo.Everyone, Delivery = RpcDelivery.Unreliable)] - but doing eg public class FXRpcAttribute : RpcAttribute, doesn't seem to trigger the codegen to transform the method into an rpc call
Am I overlooking something while defining my attributes here, or is this not achievable with the way NfGO is structured?
edit: dug into the codegen source and yeah, looks like i'd have to modify com.unity.netcode.gameobjects//networkbehaviourilpp.cs, which isn't really ideal :\
Is it possible to change ConnectionApprovalCallback while NetworkManager is already running a server/host?
I used to have something in my unity that let me fake four different instances of my game so i can test multiplayer. Once i pressed play the game would run in Unity and it would bring up 3 other windows with the game running different players and i could make on the host. I am desperately trying to find out what that was again. Anyone know?
For anyone wondering, I found it. Its not a github download like it was before when i first used it in experimental mode. In Unity 6 its caleld Multiplayer Play Mode
Its in the network manager, like just a custom network manager if you get what i mean
still cant get 2 players showing up on each others screen using netcode
think i had nit then i moved to try make a lobby with their example and i dont know how again..
also the one that does work is so delayed even on localhost, id hate ot see it across a real network
theyve made the whole thing into a nightmare, might go back to pun
Attempted to write without first calling TryBeginWrite()
soo I need to calculate size by using if(!writer.TryBeginWrite(sizeof(float) + sizeof(bool) + sizeof(i))) { throw new OverflowException("Not enough space in the buffer"); } yes?
yeah, or the use Write[x]Safe methods
Safe method checks size every write yes?
and writevalue is more performant while doing just trybeginwrite on start?
also what about reading?
if someone can tell if its correct way of reading/writing stuff
or I should just use serializevalue thing while its not that complex
yeah, it's the same in both directions, you either need to tell the reader how many bytes you expect to read or use the safe methods
it's only a small bounds check per read/write to use the safe methods, so checking the bounds ahead of time is more valuable the more frequently you're doing those operations
while using BufferSerializer.SerializeValue(ref something) I need to also check size?
iirc those call the safe methods
hmm accessing NetworkList in awake method and list is null hmm
like networkmanager in lists is null idk why
its any proper way to make networklists? I mean I do have public NetworkList<byte> _syncEffectsIntensity = new NetworkList<byte>(); but while doing _syncEffectsIntensity.Add in Awake its throwing nullrefs
if (!CanClientWrite(m_NetworkManager.LocalClientId))
They have to be initialized in Awake, IIRC.
and you should ideally be adding to them after the network starts, not before.
soo if its player object then it should be fine in awake?
I believe Awake always fires before network init on an object, so no
public override void OnNetworkSpawn() ?
Yeah, that's where it would be best to do it
finally no error spam in console aa thanks
now one action after spawning player object results of unity editor just closing
just attached debugger into unity uh oh
How common is it if instead of spawning bullets, bullets are local, and if you hit someone you just inform client you hit them?
This will make the person shooting the bullet very happy as it will always look like they hit the person they shot, but this will almost always result in the person who got shot being pissed because it didn't look like they got shot
aha ok cool, i would imagine this is the way to go for me as its more of arcade style game and is client auth.
Im running into some issues in my current setup where i hit them but doesnt show any damage on their end. ( only sometimes )
i spawn projectile, assign force, and projectile detects hits. youre throwing cards at eachother. Not sure if i should take different approach
anyways thx for the help
hi, im trying to make a lobby broser with facepunch.steamworks, i have this function that creates a lobby with Gameid unique to the game name set with SetData:
{
Debug.Log("host");
NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnectedCallback;
NetworkManager.Singleton.OnClientDisconnectCallback += OnClientDisconnectCallback;
NetworkManager.Singleton.OnServerStarted += OnServerStarted;
NetworkManager.Singleton.StartHost();
CurrentLobby = await SteamMatchmaking.CreateLobbyAsync((int)maxMembers);
CurrentLobby.Value.SetData("game_id", "TOFLOATBOAT");
CurrentLobby.Value.SetJoinable(true);
CurrentLobby.Value.SetPublic();
} ```
then i have this next function that searches for that lobby using the same gameid:
``` public async Task<bool> RefreshLobbies(int maxResults = 5)
{
try
{
Lobbies.Clear();
var findLobbiesQuery = new LobbyQuery();
findLobbiesQuery.WithMaxResults(maxResults);
findLobbiesQuery.WithKeyValue("game_id", "TOFLOATBOAT");
var lobbies = await Task.Run(() => findLobbiesQuery.RequestAsync());
if (lobbies != null)
{
for (int i = 0; i < lobbies.Length; i++)
Lobbies.Add(lobbies[i]);
}
return true;
}
catch (System.Exception ex)
{
Debug.Log("Error fetching lobbies", this);
Debug.LogException(ex, this);
return false;
}
} ```
My steam app ID is set to 480, so when I remove the specific game ID filter in the refresh lobbies function I can see other developers lobbies, but when I do it with the game ID filter I can’t find anything even when hosting the same game on another computer, is this because I need to get my own steam app ID first?
Any help is appreciated!
You would do this for slower moving projectiles like rockets or grenades. For bullets it's normal to raycast from the player on the server to determine a hit.
I don't use Steam lobbies, but my understanding is that it needs a valid Steam game ID.
I am getting an error trying to check lobby or player data. I know it takes a few seconds before the data exists but even with a null check, when i poll the lobby the data updates throw null. And it happens every poll no matter how long i wait. Any idea why?
Its happening in multiple palces but the most common is (currentLobby.Data.TryGetValue("MaxSize", out var maxSizeData))
Hard to say just from looking at the code, but I always discourage the practice of manually polling lobbies for updates to their data. Lobby Events are the way to go.
Do you have a good place to start with Lobby events? This lobbydata is really causing my headaches
Oh i think i see it. They're like normal events you can subscribe to. Thanks
https://docs.unity.com/ugs/en-us/manual/mps-sdk/manual
There's also this which helps to combine Lobby/Relay/NGO in to one easy to use package if that works with your setup.
Ive currently set it up like this. Something seems off though.
I dont see event documentation in that site but i may ahve missed it.
All of your UI changes and whatever else uses the data has to be updated within those event listeners
await LobbyService.Instance.SubscribeToLobbyEventsAsync(currentLobby.Id, callbacks);
I cant tell if this is correct. I had to wing it. do you know?
Wonderful thank you!
You can find more code examples here
For an indie game that has co-op multiplayer, is it better to provide a lobby list for players to choose from when looking for public games to join, or should I implement automatic matchmaking where you set some filters and automatically get put into the closest matching lobby?
I'm using steamworks. Currently I have a lobby list, but I'm starting to think automatic matchmaking might be better?
Usually automatic for public lobbies and then the option to make a private lobby that's joinable via code/invite
Thanks, that's what I was thinking. Need to work on implementing that
Oh yes! Thank you! Examples awlays help
If you aren't too far along, give the Multiplayer SDK a shot. It really does make things a whole lot easier. There is a migration guide if you decide to switch.
Im currently using it... I think. I had an issue where there were two relay instances and i had to uninstall one. I guess relay is built into the multiplayer now?
it's built in to that package
along with Lobby
that migration guide tells you what you need to remove
Yea i didnt realize that at first. So i had rhem all installed LOL. all my references were bugging out
Oh, if you are then you don't need to mess with lobbies directly at all. Sessions handles all that for you
an encapsulation of a Lobby/Relay/NGO instance/group
oh man. I'll gladly start my front end of my game over and do this instead. Lobbies is driving me insane
you guys rock
it just streamlines the linking of those packages together, doing a lot of the common things you have to do across those packages automatically or within a single call
Lobby can be a pain to work with and now that the above package is out, there's really no need to use Lobby directly unless you need lower level access for a highly customized solution - even then with all the constant updates that Sessions is getting nowadays, that's becoming less and less true as well
Check out the Widgets Package as well. It has a Session Viewer UI prefab you can use as a Lobby Browser
Im.... so effing glad i asked questions here first. This is a life saver.... thank you
is the widgets package i nthe package manager. I dont see it
Sessions came out after I made an entire Lobby system from start to finish lol
there's steps there to add it by name
com.unity.multiplayer.widgets
OOF
You can get it from the Multiplayer Center as well or install it by name
ah okay. I got it now. Im excited. I'll actually be able to get passed the lobby thing and go back to the fun stuff
They are excellent for getting up and started quickly, but they are not very customizable at the moment.
well this still will help a lot. i jsut need a lobby system so i can start testing with real people. and this was holding me abck big time
For quick and dirty testing just slap a Quick Join Session widget and go
There is a Unity Netcode Discord Server in the pinned message here.
Just messed with the widgets... I'm gonna go ahead and delete the lobby stuff. THis is so much better
I think ive got it. i jsut cant figure out how to access the data from playerpropertieschanged. Any idea?
You would need to loop through currentSession.Players.Properties[]
You might need to call currentSession.Refresh() first.
I am using Multiplayer Play Mode. Any time I do some code changes it says that the Network Configuration doesn't match, then I have to restart Unity and it starts working. Is there anything specific I have to do so I don't have to restart the editor?
Do i call currentSession.Refresh() inside PlayerPropertiesCHanged method?
I find with Multipler Play mode if i make a lot of changes to the code i have to uncheck the other player so the instance closes and recheck it. It rebuilds the instance including any changes
That should work
Make sure you have domain reload turned on so everything recompiles on changes
i've had a lot of problems with MPPM not triggering a domain reload on code changes on the secondary players 😦
Looked at my settings and it is set to reload by default, so it doesn't help. Unchecking and rechecking the other player did work
Yea. I think this is the main issue. Not sure what causes it though.
i guess it's something to do with the asset database on the others not being told about changes, hopefully something they'll iron out over time
I finished writing the session/lobby code. Works great but im having one issue. When the host joins the player properties are added jsut fine. But when another player joins the player property PlayerReady doesnt seem to be getting added for that player. I can see it happening in the OnEnterSession method though
quick question if i pick up a gun, the weaponholder has to have a network object as well as the player itself (so two?)
the gun, the player (and unit if the player is jsut a camera controlling the unit i.e. a tactics game) has to have a networkobject component
yeah but i dont set the gun as a child of the player itself but to the weaponholder (hands) which are a child of the player
and this requires a network object ig
I would use physics joints to attach the object to the player hand instead of reparenting
uh but my system, where the animations of the gun (including the hands) are stored on the gun, and at spawn, the players animation controller is set to the gun's one, means the gun HAS to be in the hands to be animated
Its a bit trickier but still doable without the gun being a child of the player. If you spawn the gun with ownership the gun itself can find its owner's player object and set its animation controller accordingly
I believe this should work. Which callback isn't getting triggered?
is the actual property itself not being set or is your UI just not reflecting the property's changes for the joining player
uuurgh can't i just give the weaponholder a network object?
nope. Network object parenting is a bit complicated
A NetworkObject parenting solution within Netcode for GameObjects (Netcode) to help developers with synchronizing transform parent-child relationships of NetworkObject components.
yeah but the animations wont work if the hirarchy is wrong right? if the gun and its parts is not in the hands, the gun animations won't work
If you are replacing the player's runtime animator controller, it won't care about the hierarchy. You just have to make sure the gun is in the right spot.
that's not true? if the gun is not in the hands anymore, the animation can't find the gun
(visible with yellow text in the animation)
it would be quite easy to seperate those animations tbh
if they're seperate objects the animation shouldn't really me jammed together in to one file anyway
I don't know how your system is setup, but the gun's OnNetworkSpawn() should be able to link things together if need be
not really
You can copy and paste keyframes between anim files
what the f- no that is way too much work, the point of the game is 100s of unique weapons
i animate everything related to a weapon in the same animation controller, then at start slap it onto the player. this works perfectly, but with netcode apparently not because of parenting when spawning the weapon
i don't really understand either, if i move the gun out of the hands, the gun is not a child of the animator anymore and won't work or am i missing something here
Setting up 100s of different weapons to be reliant on another model within their animations is not something I'd recommend - for offline development or multiplayer development
it's really simple, the hirarchy of the hands just has to be the same
then it will work
and i am not planning to change them
so this system will work
i hate the approach of first person models/animations not being the same as third person ones, that's too much work and just dumb
I was referring to using an AnimatorOverrideController
dies
yeah i dont see how that would help
what if i spawn an emtpy object with the script of the gun on the player, then spawn the gun model itself in the weaponholder with an rpc sendto.everyone?
btw, if i swap a weapon, can i just disable a network object in netcode or is that not possible (respawning would be dumb) or i disable the model and set a bool usable to false
The network object need to be remain enabled if it has RPCs or network variables on the object. If it doesn't have either then it might not need to be a network object at all. Just use an RPCs to Instantiate the gun object on each client for that player.
well a weapon with rpcs to shoots / attack or use abilities of it, need a network object tho i guess
or i use an interface to run the shoot function with a gun controller on the each gun, but idk if i am thinking far enough rn or if it will create problems later
Those Rpcs could be on the player instead. Leaving the weapon as a regular game object
indeed i did not think far enough. players who join later won't see the other player's weapons
how do you organize code when you want to make local multiplayer and P2P multiplayer?
for example: player object that holds some properties and can spawn animals in the world.
edit: give me a an hour to actually figure out what my problem is 😅
I usually tend to make the "Player Object" represent a connection/machine in an abstract way. This object will search/listen for different sources of input and create actual playable character objects in the game for each input (ex. player character object for each controller plugged in).
so what makes my brain melt is that I can just use the direct object reference in local multiplayer, but in a networked version I don't know how I get the actual objects using the ClientID
also, how do you make both work? My current version was built for local multiplayer only
I think I have to create 2 player objects/prefabs one without a networkObjectComponent and one with it. For the networked version I then have to move the logic to a networkBehaviour and make it use the ClientID instead of the direct object reference. Then, depending on the play mode, I choose the prefab to use, right?
The reason I recommended the solution above is because it avoids any need for separation of code or prefabs. If you're going to create and maintain what is essentially two separate versions of the game, that's a lot of work.
The other benefit to what I suggested is that it allows you to connect a client to an online game with 2 players. So you're able to do fully local offline multiplayer with two players on one machine, as well as connect those two players to an online game.
Is there an example of that somewhere? starting out with things and the light bulb is just starting to flicker (just yesterday I learned how to actually use the newtwork prefabs list and how to instantiate+spawn things)
I'm not too sure. Probably would be hard to find. Especially one that exactly matches your setup. But honestly I would say it's not too hard.
The main things to focus on are:
- One object that represents the connection/machine. This object can be pretty barebones as it only has a couple responsibilities. Connecting/disconnecting, listening for input sources, requesting playable character objects to be spawned by the server when an input is found and storing these character objects.
- Your actual playable character objects don't actually need too much special consideration. As long as you spawn them with ownership and correctly map an input source to them, they can handle pretty much all of their own networking logic themselves.
Ok, now it really sounds easy. I guess I can google how to get object references with clientId
Thanks so far 🙇♂️
Are you using NGO?
If you spawn the connection/input manager object as a Player Object, you can get it via:
NetworkManager.Singleton.ConnectedClients[clientId].PlayerObject;
and then if you store reference to the playable character objects in a script on the connection/input manager, you'd also be able to access them with only clientId
My UI changes aren’t reflecting
The property is definitely getting changed but my UI isn’t reflecting it. Could be a race condition but I don’t know how to test it
Nvm. my logic was just bad. If this helps anyone, this is the working code:
How do i set the property of the session itself? I see ISession.Properties but i dont see any overloads
The session owner can do that. session.AsHost().SetProperty()
Brilliant! How did you figure that out so easily? Im looking at the page and i dont actually see that you have to use AsHost() first
lol, I'm a mod over on the Unity Netcode Server We've been digging through the docs for some time now.
Ah! okay that makes sense.lol
if (AuthenticationService.Instance.PlayerId == currentSession.Host)
{
//host sets the session "SceneToLoad" property
currentSession.AsHost().SetProperty("SceneToLoad", new("Battle"));
await currentSession.RefreshAsync();
}```
This doesn't call UpdateSessionProperties for me. Im sure I did something wrong but i cant see what
I just debug.logged it and the property isnt getting set for some reason:
It should porbably be "SavePropertiesAsync()". I'll try that
Yea it was that. Thanks @sharp axle
Why is this giving me an error?
Are you calling this in Awake()?
Nope, a button.
Just an 'Authenticate' button
oh wait no, this gives me the error when I try to create a new lobby
That error means your CreateLobby() is getting called before the Unity Services are Initialized
How may I fix that?
You can call your Authenticat() in your CreateLobby() before you CreateLobbyAsync
Currently that function is called when a button is pressed, i dont think it'd be a good idea to change that
does anyone know of a good networking solution that has steam integration and would work well with visual scripting? i've messed around with fishnet, but a lot of the actual networking from what i can tell can only be done in actual c#
ok i did that now and it works. the only problem there now, is that i don't know how to handle weapons like bows -> where i have to hold the mouse (play and hold an animation) and then release and shoot, if i use an rpc to run the shoot function of the weapon interface
I would use a network variable for that. It can be a bool called WeaponCharging/Drawn/Loaded whatever. If it goes from True to False then you call Shoot()
i have a networkvalue that i think its properly implemented, but it is always 2 out on the client.. its like the first 2 decrements dont work.
Network Variables are sent reliably and are guaranteed to be in sync
thanks, yes i think it was just when i was printing them
thatsamazing, theyve made it easy, otherday i was confused by that lobby that as u said was over engineered, writing a simple one now.
im trying to add something to a NetworkList but i get a null when i do, error copmes from inside NetworkList inside add, if (!CanClientWrite(m_NetworkManager.LocalClientId))
but the list is initialised already, any idea why its null there?
Depends on when you are calling the Add(). You will need to make sure it's after OnNetworkSpawn() has been called.
Thanks a lot!
I can see myself getting client side prediction working somehow (I am using ngo not entities) but there is no host migration right? Idk if I heard it being in development ... or was I just dreaming
Anyway seems a bit complicated to me, but this feature feels like it makes paying for servers obsolete if the game is not in a huge scale
i have a list of games like this, but for some reason the callback never gets updated when i update the list.. availableGames = new NetworkList<GameInfo>();
availableGames.OnListChanged += OnAvailableGamesChanged;
instead i have to call refresh every few secs, seems wasteful
is there some bug doing something like this? think i saw on forum earlier public struct GameInfo : INetworkSerializable, IEquatable<GameInfo>
How often do you add to this list?
just once
You might as well use NetworkVariable instead of NetworkList then
You can just assign the whole list to the NetworkVariable and then you have to call CheckDirtyState on it. I’ve seen people have more luck with this being reliable than NetworkList
oh i mean ultimately id like many games in the list 🙂
Yeah. You can still have that.
ah nice,
i think im fundamentally confused how this works to be honest, kind of limped through it using copilot
public NetworkVariable<List<GameInfo>> availableGames = new(new List<GameInfo>());
Should work for you
will try it thanks!
And then you just have to call availableGames.CheckDirtyState() and OnValueChanged should trigger for it
so why doesnt networklist work do u think?
see all the stuff i did with the list then has errors like add etc
and dont want to change it all unless i know it would work
I`ll maybe come back to this, i should prob rewrite what i have
difficult to test without another ip lol
I don’t know. I very rarely use it. But I’ve seen many people have issues setting them up. I would check if a NetworkList of a basic type like int works. It might be something to do with serializing GameInfo
Yeh think i did read that somewhere
i think it started when i added name and desc to it
but that was hrs ago so not sure
Hey, I get no error for this code, I just don't see the client's prefab on the host (and also it doesn't get moved)
does anyone elses unity jerk a lot when testing 2 players? i know its a fast enough computer because sometimes it runs fine
is it listed in network prefabs?
and have a network obj script
im new to this so cant help much lol
Hi guys,
I am currently working on a multiplayer game and since yesterday or the day before I am getting this error message when a second player (client) joins my game session via the Lobby Service -> Relay Service...
I am using NGO 1.11.0, Relay 1.1.1, Lobby 1.2.2 and Unity 2022.3.50f.
0x00007ff7a7cf5a2a (Unity) DefaultBurstRuntimeLogCallback
0x00007ff7a73c59ca (Unity) BurstCompilerService_CUSTOM_RuntimeLog
0x00007ff8d4b25224 (0fe68df1e5ba95833e8f9a73948d692) Unity.Burst.BurstRuntime.RuntimeLog (at /Library/PackageCache/com.unity.burst@1.8.18/.Runtime/Library/PackageCache/com.unity.burst@1.8.18/Runtime/BurstRuntime.cs:137)
0x00007ff8d4b6643c (0fe68df1e5ba95833e8f9a73948d692) Unity.Networking.Transport.Relay.RelayNetworkProtocol.ProcessRelayData (at /Library/PackageCache/com.unity.burst@1.8.18/.Runtime/Library/PackageCache/com.unity.transport@1.5.0/Runtime/Relay/RelayNetworkProtocol.cs:498) AND :440
[...]```
I am getting the error on the server/host and client.
I am not the only one with the error message: there is already a Unity community post:
https://discussions.unity.com/t/received-an-invalid-relay-bind-received-message-wrong-length/1557791
Does someone know an answer for this issue?
yeah
Make sure that only the host/host is instantiating and spawning the network object
This sounds like an issue with he Relay service
Report this in the Cloud Dashboard next time you see it. And keep an eye on https://status.unity.com/
Unity Services's status page provides information on the current status and incident history of Unity Services.
guys Im kinda confused, do you use fishnet with heathen or fishysteamworks with heathen because I saw fishnet's website saying fishysteamworks is a wrapper thats compatible with heathen but arent they both wrappers? why would I use both
sup gang, plz ping me for the reply c: ❤️
I have 50 cards for each of my players
when the deck initializes it takes from those cards and assign them as needed, the card image and such~
now, sometimes I will need to spawn new cards, how should I do this?
I could make the pool bigger, make it 100 card each card pool, but I think I rather have it spawn new card prefabs
something like this
That means do I do a check for (if IsHost)?
IsOwner prefisely
has to be isHost or IsServer. the client can be the owner but can not Spawn objects
If you are using Network Object Pool, then it will expand the object pool when you spawn the objects
Sure
oi, I will check that out
later tho, today is the presentation XD :'v I'm so nervous, after today I will polish a lot of things and make the game better overall
so that's in the list now
Hello!
I'm trying to get a little proof of concept for a game working, and i'm having some trouble with synchronization.
I'm using Photon Fusion 2 and the issue i am having is that if i quickly tap any directional key, the Direction value quickly switches back and forth between the previous, and target direction as if it can't decide which direction to apply. This only happens on Non-Host clients.
mu_playerDrawer class is only responsible for displaying the changes, and doesn't modify the networked values or calls any RPCs, so i hope it's not important in this issue.
soo when I have network object which has network objects parented into that how I can spawn them also when spawning root
its any easy way via some setting?
these doors
I cant have network objects already in prefab as parents?
seems like all these objects have same global id hash
Server spawns room
Room ( Prefab and NetworkObject )
- SomeObject
-- Door1 ( Prefab + Network Object )
In this case I can just remove network objects on parent ones when root has one?
You have to spawn them both separately then you can reprarent them afterwards if you really need to. Or you can remove the network object from the child object
You are running the server on the same local machine?
Hi, so I am currently getting delayed spawning of objects between my host and client when they are running on the same local machine. The difference is spawning is noticable and longer than a frame. All my settings appears to be correct and should not be introducing any lag, I was wondering what some reasons for this latency could be? Could it have to do with differing framerate? I'm pretty new to networking so I feel like it is a very simple fix, but I don't really know what to be looking for.
You're still going through your local network which is subject to latency, it's never going to be instant.
Shouldn't the latency be at least not noticeable and within a frame of each other? Currently the delay is noticeable especially if you place both windows side by side and look at the spawning of the objects on both.
Hi, ive only used unity netcode to build my multiplayer games but i looked at photon and saw this. Does photon do all of this stuff by itself or is it like really easy to implement? Because in netcode you would have to do this all by yourself which would be very very hard. Like Client side prediction or lag compensation.
if it really that easy i might actually switch
I mean it shouldn't be anything crazy, but if it's between 10-20ms I would say that's not really of any concern.
"by itself" is a bit of a misnomer. They provide these features for you to work with out of box. Meaning you don't have to implement them from scratch. You still have to work with the features to integrate them in to your gameplay code.
There are also other considerations like when using Quantum, you are required to use their physics system and are unable to use Unity's physics.
yes, but how much time does that save you? I would say a lot. I dont even know how i would build Client side prediction or lag compensation from scratch in netcode and i didnt seem to find any useful tutorials on it either. And these things are practically necessary, i mean a game without client side prediction is basically unplayable and an FPS game without lag compensation is also unplayable.
if there was like an asset or something that would do this in netcode i wouldnt even think about switching
In theory, lots. Most of those features aren't simple topics. Was mainly answering your question of:
Does photon do all of this stuff by itself
Which is no, as I explained above. I would look at reviews and tutorials to gauge how easy people find those features to use. That will give you a better idea of if it's worth switching or not.
Depending how how important pinpoint accuracy and anti-cheat is, you could make a respectable small-scale casual FPS experience in NGO using Client Anticipation and by implementing a basic Lag Compensation system which I would say is not too hard to do with NGO.
Client anticipation is only relevant for games using a client-server topology.
i just looked at the photon docs and it seems pretty clear and simple. Unlike unity they actually give good examples that are easy to understand. But i also dont really want to switch and re-learn all the stuff i already know. The client anticipation you send me looks kinda hard and i have no idea how to make lag compensation
Also my game could be client authoritative, which would delete the need for client prediction, but i would still have to make lag compensation
There's a sample from Unity about Client Anticipation and there's plenty of resources online regarding lag compensation. Even ones that implement it within Unity
okay, i will look into that and also photon brags a lot about their extremely good performance, would NGO have some issues with performance if you had like 5-10 people on a server with lag compensation etc...?
I wouldn't think so.
Where did you hear it's really easy to implement?
Not sure what you mean actually
well they have a dedicated implementation for it
and detailed documentation on how to implement it to your game
No, you wouldn't implement it, you would use it. Your wording is confusing
yeah thats what i meant
And yea, they make it pretty easy to do CSP, and the rest.
a game without client side prediction is basically unplayable and an FPS game without lag compensation is also unplayable.
This is not true
There are tons of games that do not do any of these
and they are playable
COD and BF don't even do lag compensation. They do a broad phase sanity check.
if you had a server authoritative game you NEED to have client side prediction otherwise you would have huge delay on your own movement etc... and without lag compensation you wouldnt hit any target if it was moving and some speed.
i dont know what broad phase sanity check is
I know, I meant in general, but yes, you would need CSP if you are running full server-auth.
They let the client do a client-side check, and they make sure it's within reasonable bounds in the server (not shooting through walls, etc)
But yea, pure lag comp is a lot better. Because with this method, the devs usually do random things like artificially worsening the hit-reg of players with bad connections which is awful.
so thats why there are so many cheaters in COD
No, two of the most important cheats are almost fully unpreventable: aimbots and wallhacks (seeing through walls).
There are ways to try to detect aimbots using Machine Learning, but it still flags good players as cheaters, it's not reliable. And people have already found ways to completely go around the kernel anti cheats, etc.
Going full server-auth will not eliminate these two types of hacks.
world of tanks actually has a solution for wallhacks - it doesnt spawn the players when they are not visible
and they also dont have client side prediction so the delay on your own input is just awful
Yea that's one way to deal with wallhacks, Valorant does this too. But this solution does not fully solve the problem, because, due to latency, you still have to send objects within a big range, to avoid the issue where you move around a corner and suddenly see someone pops in front of you, etc.
I've been away for a long time. In easing back into multiplayer im learning that you need to NetworkObject.spawn anything with a networkobject or your RPCs wont work. Is there a way to just have those objects in the scene already and assign ownership to the host? Spawning them destroys the object refereences
NetworkObjects placed in scene before runtime get spawned automatically.
I believe you have to have something checked on NetworkManager, maybe Scene Management, but I believe whatever it is is on by default.
Ohhhh!! Which one is it?
NetworkManager, not NetworkObject.
Oh ! Sorry let me check
You'll also need to make sure that if you are loading the scene, you are using the Network Manager Scene Manager
THATS the problem!!!! Dear god I was going crazy. When I would run the scene as is the game worked. But if I came from another scene? Fail
Thanks guys
Has been fixed by unity staff: https://discussions.unity.com/t/received-an-invalid-relay-bind-received-message-wrong-length/1557791/5
Hey, how do I sync playerNames displayed with a TMPUGUI on the player's head? Also how do I sync material colors?
What library/solution?
NGO
NetworkVariables are a way of synchronizing properties between servers and clients in a persistent manner, unlike RPCs and custom messages, which are one-off, point-in-time communications that aren't shared with any clients not connected at the time of sending. NetworkVariables are session-mode agnostic and can be used with either a client-serve...
So I create a string networkvariable for every playername then?
Well I would make one NetworkVariable that's in a script that is attached to the player prefab
and you have to use FixedString, not string
Why's that?
And so make the script a networkbehaviour
sup gang c:
I have this script where I call SetPlayer
I have (2) PlayerHandlers btw
and this function, "SetPlayer does get called
I can confirm that cause I debugged and, you can see the "IsPlayerOwned" is been toggled on the correct player
HOWEVER! <=
it's only doing the other part, the serverrpc and such for the host
🤔 I guess it's cause I'm calling it too soon....
when it hasn't determined which player is which yet...
no clue.... 😦
Hi! So I had a question regarding scene management. When I am transition from the starting scene to scene B, I just walk through a portal. After walking through the portal my game freezes for a bit, which will be fixed later and probably covered with a loading screen, but that is not the problem. The problem is that when the client or the host interact with the portal the host's game freezes and start transitioning to the next scene, but the client's game does not. AFTER the host's game has fully transitioned to the next scene, the client's game freezes and begins transitioning to the next scene. I was wondering if this is normal or if there is an easy way that I am missing to make it so that the host and client begin transition at somewhat similar times.
Hello guys, i need ur help !
I'm trying to make the player able to hold an item in hand.
As i'm using netcode, i can't parent the network pickable object.
So, how can I do ?
I was thinking about making two prefabs of the pickable object : one that is networked and one not. Is this the right way ? Any alternatives ?
What you do is make a transform that the object should follow in an update usually
If there's not a lot of different types of objects, fake it without a NetworkObject - if there is, use joints.
I have a lot of different types of objects.
I already tried to use joints, but there are jerks
really ? it might overload the network, no ?
It wouldn't actually
Even with a lot of objects, faking it is still an option.
and usually makes any animations/transitions of picking up/dropping/interacting seem a lot smoother
thanks for answering guys, appreciate it!
so create two prefabs for each of my pickable objects, right ? 🥲
No, don't do that imo
That would be the most cumbersome way of faking it, but yeah.
Other ways would be having a gameobject pre attached to the hand that has all of your grabbable objects disabled so they’re ready to be enable when something is picked up
You could also make a dynamic system that detects what mesh is being picked up at runtime
And then instantiates it locally on every client instead of doing it via NetworkObject.Spawn()
Oh, could be the best idea
The only real reason to do reparenting or joints is usually VR where you have to be able to swing the object around dynamically with your hands - “faking” it allows things to seem more responsive and lets you be more in control of the interactions
Thanks for answering man, i'll try!
So I am working with syncing up dashing effects right now between the host and client in a peer to peer game. I am running two instances on the same machine so I'm pretty sure this much of a difference between the host and the client should not be happening. The two images below are of the client's player.
The image on the left is the client player on the host's screen, and the one on the right is the client player on the client's screen.
Pretty much how the effect is created is through my object pooling system, where if the client dashes, it requests for the object to be spawned and then synced using .Spawn on the server/host side.
That's not a crazy amount of delay - even when testing on the same machine you're always going to see some delay.
I think you're going about syncing this effect in a way that's overly complicated. There's not much reason why this effect would requires the server to .Spawn NetworkObjects for this. I would look at simply using a NetworkVariable or an RPC to indicate to all clients that this player object is dashing. Once clients receive this update, they can locally instantiate the phantom clones of the player sprite to create the dashing effect. This will always result in the effect appearing right behind the dashing player.
Ahh gotcha tyty ^^
Hello, how do I use FixedStrings as strings in networkvariables?
NetworkVariables are a way of synchronizing properties between servers and clients in a persistent manner, unlike RPCs and custom messages, which are one-off, point-in-time communications that aren't shared with any clients not connected at the time of sending. NetworkVariables are session-mode agnostic and can be used with either a client-serve...
Thanks
How do I sync TMP texts? I want to display the playerName on the screen with TMP UGUIs
I tried ServerRpcs but those didnt work
Hi there, I'm following this official tutorial about netcode for entities in order to learn the basics of multiplayer (Unity 6): - https://docs.unity3d.com/Packages/com.unity.netcode@1.3/manual/networked-cube.html
I follow the steps, manage to create a local multiplayer game, when the ghost cubes are spawned accordingly to the number of players, but I can't manage to move the cubes by pressing the arrows (From CubeInputAuthoring#SampleCubeInput), despite being correctly added to the Cube prefab.
GhostAuthoringComponant (on the Cube prefab) is set to Owner Predicted and Dynamic, with Support Auto Command enabled.
Does someone knows why ? Thanks in advance
I'm following this official tutorial about netcode for entities
hey guys just a question here i am trying to make an inventory for multiplayer but i found out not all methods work as good what is a good method for the inventory and than i mean like setting the obj invisable or destroying the object or scriptable objects
anyone know rollback netcode?
I know one or two things, do you have a question?
how would i sync animation frames
@dry maple
If you want to roll back during an animation then you would need to write your own animator using the Playables API.
Hello everyone, i have created a multiplayer chess game in unity, and for that i need timers, but the problem is each player in chess needs to have their own timer, and every time it's their turn their timer should start and the other players timer should stop, these times needs to be synched on both sides, how can i implement this using internet time or an NTP server or any other way ???
is anyone here created a turn based multiplayer game that needed timer? if so how did you manage to do that ???
How is your game networked?
i'm using nakama relayed multiplayer
Your server/host will be the source of Time for the match. I don't use Nakama but there should be a way to send Timer start and stop messages to and from the server. If you really need to prevent cheating then you can use a cloud service to store match times.
Hey, how do I enable clients to write into a networkvariable?
This approach doesn't work
in what way does it not work?
It says that client cannot write in NetworkVariables
I'm using playerName.Value in a simple function
Do they own the NetworkObject that has the NetworkBehaviour with playerName in it?
No they don't, how do I make them own it?
Those are scene objects
Probably by sending an RPC to the server when they join to get the server to assign Ownership to them
Yeah sure but whats the code behind the ownership?
https://docs-multiplayer.unity3d.com/netcode/1.11.0/about/ Documentation is your best friend for that 😛
Overview of Unity's Netcode for GameObjects for your multiplayer networking needs.
Scene Objects are owned by the server/host. You can change ownership with GetComponent<NetworkObject>().ChangeOwnership(clientId);
A NetworkObject is a GameObject with a NetworkObject component and at least one NetworkBehaviour component, which enables the GameObject to respond to and interact with netcode. NetworkObjects are session-mode agnostic and used in both client-server and distributed authority contexts.
Right thanks. I have found the problem I was looking for yesterday, but I still have something done wrong, can you check my post under?
Hi! So I am currently converting my single player combat system into multiplayer. I am working on just syncing character stats such as max health right now. My stat system right now pretty much has a main character stat manager called CharacterStats which houses a bunch of Stat variables, which is a custom class that has a bunch of important methods such as GetBaseValue and AddModifiers. I would want to maintain this custom Stat class and modifier system, but how would I even start with converting this system to multiplayer? I was thinking of creating a custom NetworkStat script where the main value is a NetworkVariable, however, wouldn't this require it to inherit from NetworkBehavior and require an actual component rather than just data values like in my Stat class?
You will likely have to rewrite a lot of your systems. You could make your stats a Struct that implements INetworkSerializable. You could then use Custom Messages if you don't want to deal with Network Objects
A brief explanation of Custom Messages use in Netcode for GameObjects (Netcode) covering Named and Unnamed messages.
Could anyone please explain me where I am doing mistake?
Profiler help
Heyy i wanted to make an online party game in which you could host a session and other people could join you via a session browser.
Is that doable with the unity networking for gameobjects? if so, how? i don't want to have to spend a lot of money on servers, most of it should be handled by the player hosting his own game.
If anyone could help me that would be awesome ❤️
^ welp no clue, but I do have another question
I usually do ServerRpc > ClientRpc > Local function
I assume I don't need that third local function, I could put everything inside the ClientRpc. Is that correct?
You can use the Relay and Lobby system for that. Check out Multiplayer Services sessions and the widgets to get started quickly
You could do it all in one function with [Rpc(SendTo.Everyone)]
a... 💀 well thanks a lot XDDDDDDDDDDDDDDDDD
I... I guess for my next project, and coming functions for this one
thanks a lot
sup gang (again)
I'm getting the debug from the server rpc, however on my client rpc, and local function~ those debug are not being casted
I don't see what I'm doing wrong 🤔
ah... I see
I did not have "Spawn with observers" toggled in my network object
sorry people xd
alright yeah i was looking into that. thank you!
Might be slightly unrelated but does anyone know the name of relay servers that hold the ip, port and name of servers for players to request a server list?
I heard the term master server but it seems like such a generic name that covers a lot of bases and nothing specific. I got a lot of things master server related
Yea. lots of things use Master Servers but that is indeed what they are called in Game Dev too

Honestly just decided to go with lobby there's no point in me even trying to make my own when something like lobby is so cheap
@sharp axle watched a vid this morning and couldnt fiugure out why the name rang a bell so much. https://youtu.be/9wNKZPoMWvw?si=aqa9K_qtfQ0SDGHN
With the release of Unity 6 behind us, let's dive deeper into the new multiplayer topology of Distributed Authority and what this means for the future of games.
Every month we host a game development related workshop online. So come hangout and meet other people in the local game development community!
Find us on Discord! https://discord.gg/Fu...
great video (:
Dats me! Thanks!
I'm gonna try to do some shorter videos on smaller topics like RPCs and Connection Events
Hello i am trying to make a grappling hook tag game with multiplayer but my players aren't moving every for themselves even when i used if (!IsOwner) return; and ClientNetworkTransform.cs script i checked the console but it didn't print out any errors and i checked a lot of videos webs but nothing so i am trying to find help here
Are you using Network Rigidbody as well?
There are many different ways to manage physics simulation in multiplayer games. Netcode for GameObjects (Netcode) has a built in approach which allows for server-authoritative physics where the physics simulation only runs on the server. To enable network physics, add a NetworkRigidbody component to your object.
yes
I have these errors but i dont think they are related to the problem because i have these since i added player movement
Hello i am trying to make a grappling hook tag game
I am using Relay/Lobby to create/connect to game for a two player game. I had someone reach out saying they couldn't connect to their spouse. Is this just an issue because they are on the same IP address? Or how does this work exactly?
It would only be an issue if they are on the same machine. Or I guess logged into the same Unity Authentication account
Hm, anything else to point to causing that issue then? As soon as I had one of them disconnect from the wifi, they said it worked/helped.
I guess it would depend on the error. Being on the same LAN doesn't normally cause any issues
I just have it set to play vs AI if they are waiting for a random time between 8-12 seconds or so, and they both just end up in AI games on LAN.
Their wifi could just be garbage if its working on ethernet/cellular
private async Task<Lobby> QuickJoinOrCreateLobby()
{
Lobby lobby = null;
int attempts = 4; // Number of join attempts before creating a lobby
for (int i = 0; i < attempts; i++)
{
lobby = await QuickJoinLobby();
if (lobby != null) return lobby; // If found, return the joined lobby
await Task.Delay(500); // Short delay before retrying
}
return await CreateLobby(); // If no lobby is found, create a new one
}
It may have just been luck. a 2 second window seems pretty tight here. Any suggestions on how this is normally handled? It tries 4 times, once every .5 seconds to join an existing lobby otherwise it creates one.
@sharp axle
You'll probably want a Lobby browser for when people want to pick a match themselves. But I've been using the Multiplayer Services SDK sessions CreateOrJoinSessionAsync(). It also supports matchmaking.
It's for matchmaking, so it wouldn't be a browser for this. I was mostly just asking how long I should "look" for a lobby before creating one.
Honestly just looking once for open lobbies should be enough. If it comes up empty, its not likely to find one .5 sec later
Is changing network variable write permissions after initialization supported? I changed a network variable's writing permission from server to owner, but I'm finding that the variable is no longer being synchronized over the network. Is there a way to restore synchronization or is this unintended behavior from changing permissions?
Why do you want to change it after initialization?
Essentially, I have a parent class whose network variables are set to server perms, but I want its child classes to let owners have permission.
Unity has a problem when I try to hide the members in the child classes, so I resorted to setting the perms manually in the start method
I’m still not really understanding why this has to be done at runtime. Why not just set the write permissions to Owner on initialization?
This is thrown when I try to set the permission to owner on initialization
Left is the parent class, right is the child class
I was suggesting setting it in the parent class only
as Owner write perms
I don’t think Owner write perms precludes the server from writing to it. As long as the server owns the object.
Thing is though, the permissions are working as expected; I tested that only owners can modify the values in the child class where the server can't, and vice versa. The only issue I see with this is that the values are not being synchronized between the server and client.
Which I would say is a pretty good indication that it’s probably not supported unfortunately.
aiyah probably :(
Any workarounds you can suggest maybe?
Worst case scenario is that I just make two separate health systems for NPCs and players, but I'd like to have a unified system if I can
I would just choose one set of write perms, declare it on the parents initialization only and set it accordingly.
You don't have to initialize health in the base class
just do it in the OnNetworkSpawn() and set it to whatever you need there
I'll fiddle with these ideas, thanks for the help 😊
Alright, so turns out the proper way to set network permissions of inherited network variables is through the Awake method, which I actually did do, but I made a logic error so I thought it was incorrect. 🤦♂️
Synchronization works and everything!
Hey guys, wondering if anyone would have any idea of how to debug something like that.
I have a linux Unity running and webgl instance.
I'm using NGO with Unity Transport configured for wss.
It works well where there are not too many people. But after like 10/15 people, I get messages like:
"CompleteSend failed with the following error code: -5"
and
"Error sending message: Unable to queue packet in the transport. Likely caused by send queue size ('Max Send Queue Size') being too small."
They are flooding the logs. Doesn't seem to be any other error.
Soon, the players cannot connect anymore. And after a while, the server seems to shut down, for everyone.
I did update Unity Transport to the latest and tried to change some of the values but it doesn't seem to help 😦
Any ideas?
You can increase the message queue size but you are likely just sending too much data per frame. The server/lhost is timing out because the network is clogged
Thanks!
Could this be because I have too many users or could this be a very bad RPC that sends too much stuff ?
I just send basic data, like the player's position, and some RPC when they are interacting
But maybe 15/20 users is already too much for the server.
Is there a way to detect when this happens and to prevent it?
I did try to increase the message send queue size but yeah, doesn't fix the issue
Probably just too many users. If you have a lot of moving network transforms then every player has to get all those positions every frame. You can use NetworkHide/Show() to have the clients only receive what is important to them.
https://docs-multiplayer.unity3d.com/netcode/current/basics/object-visibility/
What Is NetworkObject Visibility?
Thank you very much, I'll look that up
Hey. I am trying to set the spawnpoint for my co op game (two players), but for some reason it only works about half of the time
I have the default positions in ApprovalCheck and no other place to change the default position
I always get the expected values from the spawnpoint and it seems to be setting it because the player spawns in the correct place, but then teleports to 0 0 0
That can happen when using Client Network Transform. the server does not have permissions to change the player's position. I would use OnNetworkSpawn() on the player to set the spawnpoint
Sorry for late reply, I am using Network Transform
This did not fix my issue, still spawning at 0 0 0
What version of NGO are you using?
2.11
Unity 6
This is my quick and dirty fix
It runs on the player prefab
(seems to be a bug where it runs host as well as client, but the hostSpawnpoint and clientSpawnpoint are working)
That's not a bug. You're just not checking to see if it's the local player before assigning position/rotation.
I meant there is a bug in my code, not anything to do with NGO
This is the way I would do it(while checking for IsLocalPlayer). But is your Network Transform set to Server Authority or Owner?
It is set to server
nvm, its set to owner
was testing it a bit so I had it set to the wrong value
Checking like this fixed the bug with it running multiple times for the client, thanks
will test it a bit to see if it fixed the spawnpoints
nope, did not fix it, but at least now its only running once
You're on NGO 2.1.1 so trying that in OnNetworkPostSpawn instead might work?
I'll give it a go
This will work only if the Transform is set to Owner Authority. If its set to server then you need to move with an RPC
doesnt seem like I have access to it
I believe it's a protected method, not a public one.
Yeah, I am using owner and everything is set up to work with it currently
Yes, you are correct
OnNetworkPostSpawn did not fix it unfortunatly
That leads me to believe you got something else going on on your end, either in the set up of your components or in your code. Position being set in Post Spawn should not be being overwritten by anything on NGOs end.
Does your movement code for the players work properly?
Definitely something else going on there. That code will work
my movement code is very simple
I can try disabling scripts on my player prefab
got it to work 5 times in row when I disabled my scripts, seems like something I doing wrong
I believe you should also be using .Teleport on the NetworkTransform instead of setting the position on the transform directly. Setting it directly will be subject to interpolation. But that's probably unrelated to your current issue.
make sure to disable the character controller on the remote players. it will override the network transform
ok, will try both
Getting an error, how can I get authority?
You call teleport on the authority
which is determined by what you have it set to on the Component
I belive you said it's Owner
yes, it is owner
So kind of like this?
or am I misunderstanding something?
Still getting the error even thought the player is the owner :/
I got it to work by only enabling charactercontroller and movement script for the playing player
Thanks for the help 😊
hello gang
the rpc send to everyone
requires ownership?
like I did in the function below
I'm pretty sure it's false by default when you use the new attributes
oh cool
and is it the same as it was 🤔
one second let me get those professional graphics to explain myself
with Server > Client > Local function rpcs
no matter who called the function, it would be... casted by the server/host player
is it still the same with the new attributes?
or now, if I put "GetCurrentPlayerData" inside of it, it would get each player's data
if I misexplained myself, excuses. I'm tired and braindead at this point
No underlying functionality really changes with the new system. It's simply a convenience update to make sending to specific targets or target groups easier.
Client to client RPCs are possible with the new system, but as mentioned above this isn't an underlying change as the RPC still has to go to the server in the middle of this process.
So, I’ve run into an odd issue. I wrote a little networking prototype, it was working flawlessly, but suddenly clients can no longer connect. The console says the connection is going through but the screen stays black and no player spawns. Hosts client works fine, but no other clients will spawn.
I’ve tried starting my computer, double checked network manager. Again no changes were made literally just stopped. Any suggestions or thoughts on what I can try?
Are you using NGO? Are the clients on separate PCs?are any error messages showing on the client?
Yes using NGO. Clients are running on my machine, using the Unity multiplayer play mode. No errors from the client, even says that they have been connected but it never gets to the player spawn. It’s very odd
Hi, I've got a strange issue with my game, where when the players spawn in, the host spawns in the correct position, whereas the client moves to 0,0,0. The player objects work by using a sphere to calculate physics, and the player model is teleported there. The sphere is deparented on start, and has a network rigidbody and client network transform. This happens inconsistently, and doesn't happen when i disable the rigidbody on the sphere. Does anyone have any ideas of what this could be?
Are you automatically spawning the player object with the network manager? Or are you doing it manually?
Are you using Connection Approval or OnNetworkSpawn to set the spawn position? I've seen where rigidbody interpolation can cause issues like this but I thought that was fixed a while ago.
OnNetworkSpawn i spawn it on the host then set the owner to the correct clientId
The thing is, i know it spawns in the correct position because at first, i stop the player from moving until the countdown ends
As soon as it can move, it does it
Is there any way i can fix the interpolation? It seems to work when i turn it off but its really jittery
How are you teleporting the player?
I apply forces to the sphere and the player model sets it's position to the spheres position
The sphere's the only one with a rigidbody
If you want an instant change in position, you should use NetworkTransform.Teleport as opposed to setting the position of the transform directly.
Teleport isn't subject to interpolation, even when interpolation is on.
Ah okay ill change that
hi, where I can find any tutorial on new unity3d multiplayer center (so also networking in that, how works, create lobby etc. not just using scenes that unity have for multiplayer - wanna understand how it works)
Its still pretty new so there is not a whole lot out there. There are the Unite talks. I made a video on it that was linked here a few days back. You can check out the Widgets from the Quickstart tab in the MPC
can you give me link on priv? cant find
This is the latest one #archived-networking message
I know this isn't related to unity but how do I use a DNS as a website URL?
What exactly are you trying to do?
Never mind, I figured it out.
Can someone explain me, why only my host can grab and change position of object, when im trying to grab something on client its not working
Anyone know where I can find release notes for NGO 2.1? I don't see them here. https://docs-multiplayer.unity3d.com/netcode/current/release-notes/ngo-changelog/
Netcode for Gameobjects changelog and release notes
Nevermind - found it from a link in the package manager https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.1/changelog/CHANGELOG.html
do you guys know where I can get started with Unity 6 networking, especially for using Steam?
For Unity Netcode for Game objects. Follow the quick start guide and read through the docs
https://docs-multiplayer.unity3d.com/netcode/current/tutorials/get-started-ngo/
Use this guide to learn how to create your first client-server Netcode for GameObjects project. It walks you through creating a simple Hello World project that implements the basic features of Netcode for GameObjects.
My network rigidbody doesn't appear to be affected by gravity, and I can't figure out how to actually move it. If I try moving the real rigidbody it doesn't work, and even though gravity is checked it doesn't appear to have gravity.
Network Rigidbody is kinematic on clients that are not the owner
There are many different ways to manage physics simulation in multiplayer games. Netcode for GameObjects (Netcode) has a built in approach which allows for server-authoritative physics where the physics simulation only runs on the server. To enable network physics, add a NetworkRigidbody component to your object.
so I need to send movement to the server and have the server move things
That or you can request Ownership change from the server
hello! has anyone tried using CreateOrJoinLobbyAsync ?
when i run it twice with the same parameters i get http error 409 on one of the instances, while i expected it to just join the lobby that the first call created
409 is a conflict error. You might still be joined to that lobby. If you drill down into the details of that exception, you should find a more exact message
Ah that's interesting
im trying to make multipalyer with photon and i need to put "if (view.IsMine)" some where so that the players dont meve each other does anyone know where to place this
Beginners shouldn't be taking on multiplayer, and people are not going to be super willing to help just knowing the amount of explanation they're going to have to do.
But an obvious place to put that code you think you need, would be in your Update function before you read the input for that character.
can u update it?
No
why
Because of what I said here 🫴 #archived-networking message
He already gave you the answer. Just take a second to read the answer over and try to implement it yourself.
but i realy dont get it
can u make it?
No
whyyyyyyyyyyyy
Go download a sample project if you just want it done for you. I have no interest in writing code for someone - especially someone who shows zero interest in attempting to experiment or learn about the topic.
i have been trying for over 2 hours
Such is programming and game development.
You were already given the answer in a pretty clear explanation. If reading that answer really registers nothing for you, you need to take a step back and read/watch some more content about networking and/or Photon.
how would one as you say "drill down", all i get is: HttpException`1: (409) HTTP/1.1 409 Conflict
CreateOrJoinLobbyAsync will throw a LobbyServiceException in a try catch block.
https://docs.unity3d.com/Packages/com.unity.services.lobby@1.2/api/Unity.Services.Lobbies.LobbyServiceException.html
it looks like WrappedLobbyService already catches it, dunno if i can do that again
guess i can try
ok it did work, it says im already in a lobby
thats peculiar
I'm fairly certain it will still bubble up. You can the full detail of lobby errors here
https://docs.unity.com/ugs/en-us/manual/lobby/manual/lobby-error-messages
Unity.Services.Lobbies.LobbyServiceException: player is already a member of the lobby ---> Unity.Services.Lobbies.Http.HttpException`1[Unity.Services.Lobbies.Models.ErrorStatus]: (409) HTTP/1.1 409 Conflict
i gotta check if i set up unique player ids correctly i guess
i have other code which uses Create and Join separately which already works, so i figured that must be correct, i just figured the combined CreateOrJoin version looked neat
thanks for the help, now i have a lead at least
ok yeah both unity instances for some reason get the same player id, i dont think ive had this happen before
but that must be it then
so the Create & Join separate case that works is using Relay, otherwise its hard to see any difference
maybe the Relay allows me to use two players with the same PlayerId
its interesting that it allows the same playerid. i just found a case in the documentation saying i need to detect this when using ParrelSync and create different profile
anyway, progress!
Yea, if you are signing in anonymously on the same PC; you should switch authentication profiles between the instances
yep, all working now!
thanks a bunch
still a mystery why the old code worked despite being the same playerid
I’m using a linux server and a webgl client with NGO. Just started getting issues where the web client can’t connect to the game (websocket failure) but a unity editor client connects fine. Is it possible that too much network comms, RPCs, NetworkVariables etc could be preventing my browser build from connecting? Or perhaps memory usage is too high for the browser?
Network messages aren't send until after connection so it's not problem of flooding the network. Unless it's timing out after connection
Can somebody clarify ownership when using network managers PlayerPrefab?
Say I have a player, they spawn and each is assigned a client ID. In the prefab there's child objects such as a light source, ect. Does each client own it's own child's?
Unity 6's visual tool shows that yes, they do but I feel like the server actually owns them..
Any clarification would be nice! What im after is having client authority on some child objects such as the light source
The root network object is the owner of any child objects.
Got it. I think I figured out the issue. I'm not referencing the network behavior on the parent when I attach a script to the light source..
Also I want it droppable so I gotta dynamically spawn it regardless. If I'm completely wrong please let me know. Thanks
Spawned network objects are owned by the server/host by default. Unless you called .SpawnWithOwnership(). Reparenting network objects should change the ownership of them as well. There are easier ways of attaching objects to players with reparenting though
If my understanding of networking is wrong please correct me during my explanation (new to networking). So I am running into an issue in another script called WeaponController, where I need to invoke server rpc (in order to handle attack collision detection purely on the server). In order to invoke a server rpc, I need to first call .Spawn on the object that wants to invoke the rpc, in this case it would be my sword object. The code above is located in my WeaponSwitching script and is in charge of handling the instantiation of the weapon. I am trying to reparent the weapon as a child of the player, however, for some reason the weapon is not being reparented. I pretty much had 2 questions. Is it true that when dealing with nested network objects, you should initially spawn in the child network object as it's own parent and then reparent it manually, as you can run into issues if you directly instantiate a network object as a child of another network object? Additionally, is there a better way than what I am doing right now (I feel like there is a very easy solution that I am missing here)?
Yea. You can not spawn a Network Object as a child object. There are other way of attaching an object to a player besides parenting though. You could also have the RPC on the player and not the weapon itself.
I see I see. Is there a reason why the code I sent isn’t working for the reparenting though? Even if I decide not to use reparenting I still am wondering why the object is not being reparented.
probably an issue with spawning and reparenting in the same call.
I think I found the issue. Would it be because I am trying to parent the weapon under a child of the player object? Pretty much I have the player object, which is a network object, but I have a child called WeaponHolder under the player, which is not a network object.
Yea that would be a problem as well. Network Objects can only be a child of another network object
https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/networkobject-parenting/
A NetworkObject parenting solution within Netcode for GameObjects (Netcode) to help developers with synchronizing transform parent-child relationships of NetworkObject components.
If you are using NGO2.0 then you can use physics joints to attach network objects
https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.0/changelog/CHANGELOG.html#added-5
Ahhh I see I see. You mentioned earlier that there are other ways of attaching objects to the player. I was wondering what common industry practices are for this? Would one way just be to manually update the position of the weapon to follow an anchor point? Would it be easier to just change up my player hiearchy so that the weapon is a direct child of the player (the only point of the WeaponHolder child of the player is really for organization but if I wanted I could pretty easily have the weapon as a direct child)?
if im not mistaken you said weapponholder is NOT a network object right? you should be able to parent it to a network object i think, am i wrong @sharp axle ?
just not other way around
ya so the player character is a network object, the player has a child called weaponholder which is not a network object. i am trying to parent a network object weapon onto weapon holder
ahh i see. Try making weaponholder a network object, that has a variable for the weapon, does the weapon need to be networked? If so do u mind filling me in why?
I have a script on the weapon that requires RPC calls, specifically for making sure when a collision is detected on the weapon the logic following such as calling damage functions occurs on the server rather than the client. If I'm not mistaken, an object has to be a network object and spawned in order to invoke RPC calls. Also I don't think I can make the weapon holder a network object as the player is spawned into the scene not already part of the scene.
ah gotcha. So i usually do this. and this is just advice, im not an expert - Change your way of thinking from weapon holder, make it a weapon controller (networked). Have all of your weapon code on it, have your weapon visual as a child. When you spawn in, in awake or wherever you want just hide the weapon visual.
Separate the visuals. All of your code will still work even if you weapon was a blank space, or a unity cube. Need to change the visual for everyone? Send an rpc that you changed the visual.
Ah I see, so would this mean I would be created a WeaponController object that is separate from the player character (and just have it follow the players hand or something like that)? And when I need to make changes to the weapon, whether it be a buff or equipping another weapon, I would simply use RPC's to change the visuals and other components?
kinda yeah. Controller should be child of player though.
just with visual hidden
Wouldn't we run into the same problem of nested network objects though if controller is a child of player and both of which are network objects (since my player is spawned in and not a scene object)?
Weapon controller wouldn't need to be a network object, just a network behavior. If the weapon is already attached to the player prefab, it doesn't need to be a network object either. Any child behaviours take the parent network object as their own.
If this is an object that is picked up and dropped, then if would suggest using rigidbody physics joints to attach them to players.
In addition to the standard NetworkVariables available in Netcode for GameObjects, you can also create custom NetworkVariables for advanced implementations. The NetworkVariable and NetworkList classes were created as NetworkVariableBase class implementation examples. While the NetworkVariable class is considered production ready, you might run i...
I believe it's also built in that you can use a struct of primitive types to group things
I've seen people talking about host migration for NGO but I cant seem to find it on the docs or anywhere (I'm only seeing peoples' custom made host migration solutions). Can I get a link please?
Also any talk about experience with host migration would be awesome with stuff like how seamless the transition is or if there's any difficulties
The only built in Host Migration is through Distributed authority
Distributed authority is one possible network topology you can use for your multiplayer game.
hey guys in debug code ends in yield return www.SendWebRequest(); and i am not getting any debug log after this the payload i am getting is working on postman though.
this is where i am calling coroutine
has anyone managed to run the NGO+Multiplayer Widgets sample on a WebGL build with Relay? It's basically the most minimal test of NGO with Sessions (Lobby) running.
I'm trying in Unity 6, and a weird aspect is that it technically works as long as I create the session in the Editor and join it with the build (even if the "Joining Session..." log is never followed by the "Joined Session: <id>" log). I can move one player in each instance.
Buuut, I would need for the Create Session button to work in the build as well. There is no error to speak of, it just never ends Joining appropriately, so it never gives a Join Code to copy.
Otherwise, affirmation from anyone that has managed to run the Sessions with WebGL Relay in any of their projects would be nice to see, as I have not found any sample online that gives me any reassurance :/ .
I've run it with Distributed Authority and Webgl.
nice! that needs a dedicated server however, I'm aiming to have some "serverless" games running with Relay.
My suspicion right now is that the async await that the template uses on the EnterSession function just never finishes on browsers. are you yourself using the SessionManager.cs that comes with the template or you tweaked it?
alright, I confirmed that suspicion with a minimalistic test that I saw on this thread:
https://discussions.unity.com/t/async-await-and-webgl-builds/665972/70
Task and await just does not work on browser :/. the issue is a Unity bug and does not have to do with Networking so I'll stop asking in this channel. Thank you for the quick reply @sharp axle !
Distributed Authority has no servers actually. Just the DA servers similar to Relay
oh really? then I completely misunderstood Distributed Authority, I must look into it more, thank you!
@sharp axle do you per chance have any Task with await on your code and it's working on the build?
The Distributed Authority Quick Start guide also has one of those (in CreateOrJoinSessionAsync).
https://docs-multiplayer.unity3d.com/netcode/current/learn/distributed-authority-quick-start/
I didn't change any code. I set the connection type in the Widget Configuration asset. Check WebGL in the Unity Transport
oh for DA, I did have to manually change the transport to Distributed Authority Transport
ok thank you I will test doing that and see
cool! its nice to see I can choose DA and it gets to the same point of functionality but I'm seeing the same exact issue.
However if it works for you without changing any code then maybe it has to do with my browsers in particular or some setting, and I don't need to change the Tasks code.
any example for project structure and networking? I mean I have offline game, wanna change it to multiplayer + add gamemode mechanism (timers, points). it's kinda fps, I wanna make it hosted by player
For NGO, you can check out the Bitesize samples Or Boss Room if you want to see a larger architecture
The Bitesize Samples repository provides a series of sample code as modules to use in your games and better understand Netcode for GameObjects (Netcode).
Learn more about installing and running the Boss Room game sample.
hey people just a small question how do i make it a object is invisable for all players when something happens?
Lots of options. NetworkVariable to keep track of whether it is visible or not, RPC to toggle off any visual elements of the object, or Object Visibility
What Is NetworkObject Visibility?
i want it like if i turned it on or off in hieracy
The first two options I explained would be able to achieve that.
thx it workedd
Is there a way to put NGO in some sort of stasis? When the host disconnects I don't want NGO to do anything about it unless I tell it to
The idea is I want the person behind the host to host a server but since absolutely nothing is gonna change I wanted them to host with an identical scene and then others can join but I guess it wont be as simple as that
If I cant find a way I guess I'll just make my own stuff with LiteNetLib or something. Having to pause the flow because one person left is annoying and really ruins immersion. With LiteNetLib I can probably just treat the next host as the host and that's it
You’re basically describing the need for a dedicated server. Host migration isn’t as simple as “treating the next host as the host and that’s it” in any networking solution.
I mean it seems like it would be so long as your codebase is versatile enough but what I'm describing would probably require a direct connection between all players
I was thinking the host was the only one clients would listen to and so the clients could switch who the host was relatively easily so long as the new host actually acts like a host
GTA pulls off something similar afaik but it's also why they had huge issues with security
When the host disconnects, the network ends. Same as if a dedicated server crashed. You could have all network objects be invisible ghosts that puppet around local game objects, that way a network object despawning will not effect the local objects
Unless you were to freeze the network and every client's game world, have the host send all critical info to the next host and then allow the host to disconnect when that's done - it is not as a simple as a "switch". And that is not a realistic solution to rely on since a host disconnect will often be someone closing the application or crashing.
When a host disconnect occurs you are asking all of the remaining clients to cobble together and agree upon what the state of the network and game should be. This is not simple as at any given moment in time, clients x, y and z will all have slightly different network and game states.
I would explore using Distributed Authority if this is that critical to your game.
Distributed authority is one possible network topology you can use for your multiplayer game.
What if there isn't any critical info? It's meant to be p2p so my plan was all clients had a list of all players in the session ordered from first to join to last and whenever the host was unresponsive or something went wrong they switched to the next person in line
That's entirely possible if you don't care about the other clients who are not the host rejoining in a slightly different game state than they were before the disconnect.
That being said, that's still going to require a good amount of work to implement.
so IMO you'd be better of exploring something like DA or just accepting the fact that if it's casual p2p, that host disconnects just happen sometimes.
Distributed authority isn't quite what I want from what I understand but I guess yeah I might have to accept host disconnects sometimes. Unfortunately I'm not old enough to have a job yet so I cant really support dedicated servers or distributed authority money-wise so p2p with lobby has been my go-to for a bit
As annoying as it is to have abrupt host disconnects friend groups are the target so my options are probably let people host their own dedicated servers outside of the game or the friend group will probably collectively agree on a time to get off the game so it's probably less disruptive than I'm thinking
Distributed Authority's free tier just like Relay's is extremely generous. You'd have to be looking at 100s of daily players before paying a cent.
and unless I'm missing something about your game and setup, it achieves pretty much exactly what you're wanting.
Yeah sorry I skimmed over distributed authority last time but I just gave it a thorough read and it does do pretty much what I want
I'll look into it I suppose. As counter-intuitive as it is I've always opted in for safety when it came to subscription based services like DA or Unity's other services despite the fact I really doubt I'll be reaching 100s of players. Maybe it's time to just use common sense and go for it
morning! I currently use relay with join code to join two players, im looking to be able to start game, click 1v1 quick join, and anyone else who clicks that gets matched.
Do i need to look into lobby stuff for this or can it be simpler?
It doesn't get much easier than with Multiplayer SDK Quick Join
Sorry for the premature question, havent had my coffe yet. Found this link right after i sent lol. Thanks man!
hi, im using a docker container to host a linux server build of my game using nfgo and unity transport
for some reason, i can only connect with web sockets enabled
if web sockets arent enabled on unity transport then it just doesnt connect
however, if i use the windows server build outside of docker, it does work
ive tried every combination of ip and docker network i can think of
tcp connections pass through when i test with powershell
so ive sorta ruled out docker as the source of the problem
which lib is most low cost(where 1 player is host and others just join lobby and play) + quick game option to just join random to lobby and start when there is X players?
GetNetworkObject(OwnerClientId);
is this right? Or is netowrkid different from client id
Its a not Library you are looking for but a Service. Epic Online Services are free to use and Steam P2P just requires the $100 developer fee. The Unity Relay and Lobby services have a very generous free tier that indie devs are unlikely to go beyond.
Sounds like you want to use NetworkObjectReference
Brief explanation on using NetworkObject and NetworkBehaviour in Network for GameObjects
woah this is different but cool, so i can passthrough players on here. Thanks
More so i was just wondering if the (netowrkid) in the function " GetNetworkObject(networkid) " == client id?
like if i said
Playerhealth health = Getnetworkobject(ownerclientid).getcomponent<PlayerHealth>();```
Is that correctly getting the client id or is networkid i seperate thing?
those are different. a client can own multiple network objects. If you are trying to get the Player Object then this section is what you want
PlayerObjects are an optional feature in Netcode for GameObjects that you can use to assign a NetworkObject to a specific client. A client can only have one PlayerObject.
ahh ok thx!
for anyone that finds themselves in my situation in the future, where Creating a Session does not return a code, or Threading tasks in general don't return a callback in a WebGL build, the way I got it solved for myself was just by installing this package from git, changing no code otherwise:
https://github.com/RageAgainstThePixel/com.utilities.async
If that's not enough for your issue, you might want to instead try this other one (altho for me in Unity 6, I could never make the WebGL build work with it):
https://github.com/VolodymyrBS/WebGLThreadingPatcher
I just discovered this myself and came here looking for confirmation. Have Unity acknowledged that addressable do not work with NetCode and have a timeline when they will support? I cannot express how frustrated I am with Unity as literally any other multiplayer tool works with Addressables. Please tell me I am wrong and all I have to do is x or y.
Addressables work just not loading scenes through addressables. There is a PR on the Netcode GitHub that seems to address this but I've not tested it
Would you be able to link me to that PR?
Found it
I am not overly familier with this side of Unity. Does this mean it is being worked on or is something I can try now?
NGO is open source so anyone can make contributions like this user did.
Does this mean we are waiting for a review before we can try?
You can pull it yourself and merge it. Those reviews are to merge it with the main branch for official release
Thank you
Obviously make a backup before making any major changes
I had a question regarding ownership. Would I want each respective player to own the weapons they pick up? I was just wondering what the common industry standard is when it comes to handling object ownership. (Planning on making my game a casual game so I don't really care too much about cheating)
Really depends on what code you have running on the weapons.
The code I have on the weapons control most of the weapons functions like cooldown/combo management, detecting overlapping colliders, applying damage.
There are lots of ways to handle that. If you are applying damage on collision, then it doesn't have to be a network object at all. The collision logic can be on the player and it can grab the damage information from the weapon.
Hey guys Im kind of new to unity and Im trying to figure out some netcode stuff. Do any of you know how IsServer could come back as false after running NetworkManager.Singleton.StartHost()
Depends on when you are checking it. That value doesn't get set until after OnNetworkSpawn() is called
Seriously? shoo did not know that
What I'm trying to do currently involves, calling startHost() and switching to a different scene containing network objects. But these objects OnNetworkSpawn() events are not being called. Am I missing something here?
Make sure you are using Network Manager Scene Manager
https://docs-multiplayer.unity3d.com/netcode/current/basics/scenemanagement/using-networkscenemanager/
Netcode for GameObjects Integrated Scene Management
Share !code correctly. This should be shared as a large code block.
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
idea is firstly selecting a unit, then clicking on a tile to create a temporary unit image, then if player clicks on that image, unit goes there
but the thing is, when clients click to units, nothing happens
it only works on the host
i am using unity netcode and unity transport
Do you actually execute this code on the client?
well, i figured out now
i started client from unity editor, not host like i usually do
and i got
NotServerException: ConnectedClients should only be accessed on server.
Unity.Netcode.NetworkManager.get_ConnectedClients () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.9.1/Runtime/Core/NetworkManager.cs:186)
InGame.SelectUnit (Unit newUnit) (at Assets/Scripts/InGame.cs:129)
InGame.OnClick () (at Assets/Scripts/InGame.cs:34)
InGame.Update () (at Assets/Scripts/InGame.cs:19)
Heya! I’m making my “copy” of CS:GO in Unity(2022 LTS), but can’t decide what Networking solution should I use. Can someone tell me what’ll be better to use? The game will have Matchmaking, Ranks, Lobbys and etc.
Currently I’m thinking of using FishNet with Steam.
Any of them can handle Team Shooters. It just depends on how much work you want to put into making a client prediction system for competitive multiplayer.
Most services like Matchmaking, Leaderboards, and Lobbies are also library agnostic and mainly come down to price.
I have this code, it is meant to make the movements and notify it to all clients. but it only works on client, other clients cannot see the changes
i got stucked really bad
need a hand
solved it nvm
Hello! I'm using Photon Fusion 2 and i'm having trouble getting VR Synchronisation to work.
I have a head object, and 2 hand objects, being driven by Tracked Pose Drivers, and XRControllers, then synchronized by NetworkTransforms, but for some reason only the Host is able to move their objects, while the clients can't move them at all.
Could it be that the NetworkTransform does not respect the input authority, and only the StateAuthority?? If so, how would i go about changing that behavior?
Hi, was wondering a good tutorial vid to start for making a multiplayer game in unity 6?
i plan on making a turn-based tactics online game with a handful of friends of mine so I imagine netcode requirements will be minimal
VR stuff is very specific, you might want to join the Photon discord
They gate the photon discord behind a paywall
:(
State vs Input authority is going to be very specific to Host vs Shared mode
Not the public one
I am one of the original devs of Fusion btw, and I started the discord servers for Photon
So I am not making that up LOL
Oh!? Cool! :D
Photon has two discord servers, public and circle
Honor to talk!
Is there a source i could find the circle one?
Circle is paid, the public is open to anyone though
Ah! I see!
It might require a photon login to exist to validate you as a user is all
So the one linked in the webpage is the circle one?
But that is free, just may need to have an account on the website
Gotcha!
Not sure, I don't work for Photon now, but I would expect the link to the discord to be for the public
Loading into it. Great
https://forum.photonengine.com/discussion/9898/is-there-an-official-unofficial-photon-discord-server-around you ended up with that following this link?
@vagrant garden not sure who to ping, but are there any obstacles currently involved in people joining the public discord?
that looks like a discord problem and not a photon one
I'd just retry
Link to join the Photon discord is in the pinned messages here btw.
You can use Netcode for Gameobjects or if it's asynchronous multiplayer then you can use Cloud Code or other serverless architecturs.
anyone got any tutorial/examples of how to use [EOS] EpicOnlineServices in unity? I mean to create lobby and transport way?
gotcha, thanks
question and sorry if this sounds pretentious, is there a way of a free server for unity games with a small player count (like at most 5)?
Relay is not a dedicated server but is a popular choice due to it's simplicity to set up and its generous free tier.
sanks
Hi, so I was actually planning on switching to fishnet from NGO. I was just wondering what some peoples opinions were on it who have worked with it. Also I was wondering before making the swap, if anyone knew the licensing around it. Is it okay to use for a game that I am planning on publishing on steam, I know that the licensing around open source code programs can be tricky at times.
it has similar features to many other networking solutions, but the main difference is that it has support out of the box for client prediction if you have a server authoritative game, and, in my opinion, more quality of life features. Also, it wouldn't be too useful if you couldn't publish your game with it! It is fine to use both the free or pro versions for commercial projects. Everything third party library it uses has the MIT license, and it itself is free to use / modify / redistribute (as long as you don't have the paid version, obviously you can't distribute that) https://github.com/FirstGearGames/FishNet/blob/main/THIRD PARTY NOTICE.md
I think it is one of the better options for real-time games if you don't plan on writing your networking with something like LiteNetLib
although if you are switching from NGO just because the networking gets convoluted, that is not something you can escape from with most of the Unity-specific networking frameworks (at least all the ones I have tried in the past). They will all have the same issues (one-size-fits-all style) since they can't cater to your specific game
client prediction of fishnet does not even work, it's buggy and jittery af
fishnet is not MIT licensed too, you can't redistribute it, it's not even legally clear if you can modify it at all
NGO supports host migration
which is very useful for coop or indie games
fishnet does not, neither mirror
We have a very negative opinion about fishnet. It claims to be stable when it's very buggy. The creator is banned in here for promotion fraud .
fishnet is not open source too
