#archived-networking

1 messages · Page 3 of 1

summer anchor
#

he is using uNet

#

and the video is 7 years old 😂

#

string _netID = GetComponent<NetworkIdentity>().netId.ToString();

#

is that correct?

fossil heron
#

Can someone help me with unity playfab guilds/clans system? Need help.

olive vessel
gaunt zinc
#

is there someone avaliable? I have this issue:

#

nvm the ClientScene got changed on mirrors documentation

meager dirge
#

Hello, so I have been learning unity for the past 6th months, and I wanted to create a multiplayer open world game. I am at the point where I have made a basic player character and I need to create enemies.

If someone would give me advice, show me how you learned, or show me their code so that I could learn from that that would be much appreciated!

I can share my project files/provide more detail on my project if that helps. I have also done research on how normal single player enemies work and tried that, unfortunately, I couldn't figure it out.

Feel free to DM me or reply to this message! Thanks!

weak plinth
# meager dirge Hello, so I have been learning unity for the past 6th months, and I wanted to cr...

A: I am currently learning from tutorials I look for depending on the things I need, and try to absorb the information of how the code works and what it does, for me to reuse that information later, and also a huge help from this server
B: My advice is to stay consistent

C:If you want multiplayer, there are some tutorials on youtube on how to make multiplayer.

D: If you want to make enemies I would recommend you to start by making a basic AI that follows the player

blazing cloak
#

My client rpc method is not working and is only called on th host client. The method has the [ClientRpc] attribute, it has the ClientRpc suffix, it is called within a NetworkBehavior and the NetworkBehavior has a NetworkObject on the same gameobject. Is there anything I am missing?

flat mango
#

Hi All,

I am currently making a game in Unity that utilizes the Google BigQuery SDK (installed via nuget within my Unity project). I was able to get the game to successfully run the API calls and get the appropriate responses for my MacOS build (tested on TestFlight and works great). However, the same API calls don't seem to work when I build my game for WebGL or Windows. Does anyone have any idea why this may be the case? Is there a certain WebGL or Windows build setting I need to enable for this to work?

Thanks in advance!

weak plinth
#

is fishnet the best networking api?

#

or is it ngo?

austere yacht
weak plinth
austere yacht
#

if you need a lot of handholding during development pick one with a good community or paid support

#

if you need the library to be stable and still supported in 5-10 years, pick one that is backed by a large, successful and well funded company that is committed to supporting it

#

if you want to make an MMO, don't

summer anchor
#

is there a way to open multiple test games inside unity without having to keep building it?

upper grotto
#

There's ParrelSync which makes a copy of the project folder which it keeps synchronised, and runs that in a second unity instance, but I have not tried it in Unity 2021. In some versions you have to turn off directory monitoring.

pallid hollow
#

hello guys,
Im making a multiplayer game and would like to add IP:Port connection, I didn't find anything online. I'm using Netcode V1.0.0

I'm using the default code provided by unity, here is it :

startHostButton.onClick.AddListener(()=>
{

  if(NetworkManager.Singleton.StartHost())
  {
    Debug.unityLogger.Log("Host started...");
  }
  else
  {
    Debug.unityLogger.Log("Host could not be started...");
  };
            
});

startClientButton.onClick.AddListener(()=>
{
  if(NetworkManager.Singleton.StartClient())
  {
    Debug.unityLogger.Log("Client started...");
  }
  else
  {
    Debug.unityLogger.Log("Client could not be started...");
   };
});```

thanks you  !
summer anchor
#

What is the best way to sync audio? my fire pistol runs on the client, which plays the sound locally, but i want other players audio listeners to pick it up so they can hear other people shooting too

honest marsh
#

Hello everyone, I have a strange issue. I'm using Netcode for gameobject and I'm trying to quick join a lobby, if there is any, or alternatively create a new one automatically.

#

public async void FindLobbyAsync()
{
try
{
QuickJoinLobbyOptions options = new QuickJoinLobbyOptions();
Lobby lobby = await LobbyService.Instance.QuickJoinLobbyAsync(options);
Debug.Log("Lobby found");
}
catch (LobbyServiceException)
{
Debug.Log("Lobby NOT found. Creating a new one.");
await LobbyService.Instance.CreateLobbyAsync("New lobby", 8);
Debug.Log("Lobby created.");
}
}

#

Now the strange thing is that if there is no lobby, the system throws an unhandled exception (NoOpenLobbies), but enter the catch block anyway.

#

So, the first question is ... did it catch the exception or not?

gusty fjord
#

Trying to make a door. Works fine overall, but when the door is opened on one client (default is closed) before another client joins, the new client still sees the door closed. Door opens by rotating a transform (NetworkTransform attached with syncing y rotation selected). When the new client joins I print out the networkvariable's value and the door transform's rotation, which are both correct. The transform just isn't actually rotated that way on the new client. Door script: https://pastebin.com/kBPi0BtL, character calls Interact() to open and close the door. What am I doing wrong?

bright mauve
# pallid hollow hello guys, Im making a multiplayer game and would like to add IP:Port connectio...

I did not use netcode over a year (used fishnet for the time until release)
but usually all transport data are saved under a specific transport object,
you can try this one:
https://docs-multiplayer.unity3d.com/transport/2.0.0/api/Unity.Networking.Transport.NetworkEndPoint/index.html#port

(add using unity.networking.transport) and for local network (same router) use Ipv4 adress and port

bright mauve
gusty fjord
bright mauve
# honest marsh

I'm guessing that unity only debug.logs the error but the rest of the code continues to work.
I did not use this system before but there is probably a way to handle LobbyService.Instance.QuickJoinLobbyAsync(options);.

bright mauve
gusty fjord
#

Sorry, to be clear, the first client is actually the host, if it matters

green moat
#

hey folks, I'm new and I have troubles with my animations in multiplay. maybe someone can help me?

pallid hollow
gusty fjord
summer anchor
#

how can i send an audio source, to the server and then to all the players without having to do a whole function for each sound?

bright mauve
summer anchor
#

such as when my player shoots, i want everyone to hear it, not just him

bright mauve
gusty fjord
#

DoorState is a NetworkVariable in the script I linked. Value decides on how the transform should be rotated

bright mauve
summer anchor
#

Cheers mate ill have a look, been stuck on this for ages now haha

pallid hollow
#

I even tried using my external ip, and setup port forwarding on my router but nothing

bright mauve
pallid hollow
#

yeah this one

bright mauve
#

alright, copy that to the other computer and make sure you are on the exact same port.

a problem that could cause this is from the firewall, I would disable it temporarily just to check as it can be the issue.

green moat
#

hey guys, if you have time maybe you can help me with my issue... I got a simple 2d movement and animation. but my client stuck in the position and cant move, but my host can...

pallid hollow
bright mauve
bright mauve
# green moat

did you make sure the second client is the owner of it's own player object?

green moat
green moat
bright mauve
#

@summer anchor if you need help feel free to ping me here, not in dms :)
and there are no dumb questions, there are dumb answers and I will try my best to not provide them here

pallid hollow
bright mauve
summer anchor
#

Sorry, i get the error to install git on my system

bright mauve
#

did you make sure to attach textMeshPro components instead of Unity.UI ones?
make sure there are no spaces or empty strings
and try to debug.log the string.count of the adress and port and count the adress digits yourself to make sure everything is correct.

bright mauve
green moat
bright mauve
pallid hollow
bright mauve
#

(in runtime, after changing the value)

pallid hollow
#

I just have this

#

"Ip" is the input field but since the value is override it doesn't matter

#

log level is set to developer

bright mauve
# green moat yeah I'm the owner

this is on the second client, right?
try adding debug.log("Test x"); to the PlayerInputs(); function.
see if the second player enters it or if the first one does as well.
also debug.log the movement values and see where it fails

bright mauve
#

sorry,
@pallid hollow can you try this instead?

NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(
    "127.0.0.1",  // The IP address is a string
    (ushort)12345, // The port number is an unsigned short
    "0.0.0.0" // The server listen address is a string.
);
green moat
bright mauve
green moat
#

on my host everything works fine

#

just on my client the player animation works, but my player doesn't move

bright mauve
summer anchor
#

Yonatan, do you know where exactly in boss room i should be looking? struggling to find and code that relates to sounds

#

besides local sounds

bright mauve
# green moat

I never seen something like this before happen naturally,
I am guessing 2 things:

  1. you have a script that makes the player get stuck at a set position (probably 0,0,0):
    so the player is indeed moving but you are updating his position to 0,0,0.
    you can check that but going to the second client in editor and than moving the player manually with the move tool.

  2. the movement is server authorative, which means the client needs to send the server his data and the server will be the one who updates the client.
    you can check if that is the case through opening the host in the editor and the player on the build.
    than try to move the second player through the host in the editor and see if it updates for the second player and the host.

bright mauve
summer anchor
#

yeah thats what im hunting for

#

on the plus side, im now backing my project up on github xD

pallid hollow
#

so nothin as changed

#

I don't have anything to add in the code when I start as host ?

#

because I'm supposing that the code you sent me only execute when I start as client

#

but I might be wrong

green moat
bright mauve
pallid hollow
#

it's working dude

#

I pasted your code on both host and client connection and it's working

#

working on two different computer too

#

thanks you so much !!!

bright mauve
bright mauve
green moat
bright mauve
green moat
bright mauve
#

I mean literally with the move tool

#

not through code

green moat
#

yeah i know^^

patent fog
# honest marsh Now the strange thing is that if there is no lobby, the system throws an unhandl...

NoOpenLobbies is one of the possible reasons of the LobbyServiceException (https://docs.unity3d.com/Packages/com.unity.services.lobby@1.0/api/Unity.Services.Lobbies.LobbyServiceException.html#properties)
But there's more : https://docs.unity3d.com/Packages/com.unity.services.lobby@1.0/api/Unity.Services.Lobbies.LobbyExceptionReason.html
So yes you will catch when there's no more lobbies, but if you don't further investigate the reason response, you'll even catch ANY lobby error exception. For example someone unauthorized or already connected to a lobby, if able to launch multiple requests, could massively trigger creation of new lobbies.

#

And indeed your debug logs are printed in the console, so yeah your catch block is executed

bright mauve
# green moat yeah i know^^

Well today I learned something new.
In netcode NetworkTransform is automatically Server Authorative Movement.
Aka each client send the server their movement data, the server moves the clients locally and than sends the clients an updated situation to render.

try removing the NetworkTransform component and switch to ClientNetworkTransform.

#

this should make it client Authorative as the client is the one moving and sending the data to the server and reply to everyone on how to render.

summer anchor
#

Has anyone got an example of how to play audio over the network at a certain players location?

blazing cloak
#

Hi. I get a wierd warning when I try to use a client rpc on unity netcode for game objects. The client rpc method does not work but rpcs in other scripts work fine. The script that is trying to run the rpc is a network behavior with a network object and the method was copied from another script where it works (it just says pong in the console). Anyone know why the rpc in this script does not work?

civic flicker
#

hello, i have two players on my game, but when i put animations on them, they are both synced. Is there a way to only have one player move and the other stay still (as in, they have different animations based on player input)?

bright mauve
bright mauve
civic flicker
#

ohhh i see

#

i'll check it out

#

thanks!

bright mauve
#

it could be that it is attached to a networkObject that does not spawn correctly or is only instantiated for the server and not a client...

blazing cloak
bright mauve
green moat
#

is it possible that a friend from another network join my multiplayergame when i install hamachi and configure unity to the hamachi ip?

wide girder
green moat
#

but if i give him my build, I need an IP address where he can connect right?

wide girder
green moat
#

my goal is to create a mmo and a dedicated server, that's why i wanted to test it with hamachi

#

i dont want to use photon

olive vessel
#

If the server is hosted on your network, you'll need to port forward

green moat
#

ok, so it could possible work with open ports and a hamachi ip right?

olive vessel
#

I have no clue what hamachi is

#

If you open the port, he can join via your public IP

wide girder
#

Hamachi is for simulating local network. I've no clue why they bring it up here...

green moat
#

ok, are there preferences for the ports that i should use?

olive vessel
#

Generally I go with 7777

green moat
#

ok

olive vessel
#

But there's all the ports

wide girder
#

Unless you have firewalls blocking ports, you shouldn't need to do any manipulations with the ports.

green moat
#

ok then I'll test it

#

thank you

weak plinth
#

How does matchmaking in games work

#

Like the player has to press a button

#

THen the game searches for other players who also pressed it

#

And then puts them in the same lobby

#

But how does it work, after the button is pressed

#

Is it neccesary to create your own matchmaking server or how are matchmaking servers created

austere yacht
# weak plinth Is it neccesary to create your own matchmaking server or how are matchmaking ser...

When the button is clicked the players Info about what type of match they want to play (class, skill rank, ping) is posted to a matchmaking server, the server stores it and waits for other people to post their match requests. every time a new player posts such a request the server searches the existing requests for a close match of parameters (you define what those are). Once enough matching players are found in this way a match dataset is created that all the players in it can retrieve. It contains the info for connecting to the match server

#

That matchmaking server usually is just a simple web api

#

you can code your own or use services like playfab with readymade matchmaking that you configure your needs

weak plinth
#

THank You

#

But, if you want to create your own matchmaking server, is it neccesary to have a server set up and is it hard to program it or is it just easier to use PLayFab

wide girder
# weak plinth But, if you want to create your own matchmaking server, is it neccesary to have...

You need someone(some machine) to handle connecting clients together/to the lobbies. Otherwise how are they gonna match each other? Check every single IP address and port on the web untill they accidentally stumble on the right address?😅 That's basically the job of the server: it provides an access point known to all clients and handles connecting them to the same environment.

As for creating your own server, there's like a full fledged profession for that - backend engineer. So it's definitely not easy.

#

Thankfully there are complete solutions like netcode, photon, mirror, etc that do it for you.

weak plinth
#

Ah

#

So OK

#

So Ishould just use like PLayfab or something like that

gusty fjord
#

Netcode for Gameobject: BossRoom uses a unique identifier to keep track of users reconnecting. That identifier is sent by setting NetworkManager.NetworkConfig.ConnectionData before starting the client. Am I correct saying that this data is then only available through NetworkManager.ConnectionApprovalRequest.Payload in the approval check and not elsewhere? I can not find anything else

wide girder
#

I'm not familiar with playfab, but yeah.

weak plinth
wide girder
weak plinth
#

Like for Playfab I found this:

#

"MatchmakingQueue": { "Name": "MyFirstQueue", "MinMatchSize": 2, "MaxMatchSize": 2, "ServerAllocationEnabled": false, "Rules": [ { "Type": "StringEqualityRule", "Attribute": { "Path": "Build", "Source": "User" }, "AttributeNotSpecifiedBehavior": "MatchAny", "Weight": 1, "Name": "BuildVersionRule" } ] }

#

But do I have to write inside of my scripts or what?

#

(Or does it do magic like the unity multiplayer solution)

wide girder
weak plinth
#

OK

austere yacht
# weak plinth OK

Generally a networking library like netcode/mirror/photon fusion will do nothing for matchmaking. Playfab and unity game services is a completely different type of thing, it’s a service for scaling your game, they typically include hosting servers, databases and various APIs for implementing features that are not real-time (matchmaking, shops, inventory)

summer anchor
#

Has anyone made a network audio component? sort of like the network animator that sync all the animations, after something like that but for audio

heady locust
#

Hi.
Can we run Photon server on Unity Game Server Hosting?
Dose anyone have such experience?
Or maybe there is other way of running Photon on Unity Game Server Hosting?

gusty fjord
heady locust
heady locust
#

Lets say I have created Unity Game Server.
And for example I have 4 rooms each has 3 players. Overall 12 players playing the game at a time.
Does it mean there would be 4 running instances (servers)?
Does it run a new server for each room?

civic flicker
#

hello guys, is it worth it to use relay for a game where the one player is the host and the remaining ones are the clients?

#

4 players max

stiff ridge
# heady locust Lets say I have created Unity Game Server. And for example I have 4 rooms each h...

It depends.
We run Photon Servers on the Photon Cloud for everyone to use. If you don't need to customize this, you can use it. The Photon Servers run a lot of rooms each (but don't run Unity itself).
You usually don't run Photon Servers on services like Multiplay but you'd run those on baremetal machines.
With Fusion, you could build a Unity instance as Server and run that per session/game-instance on services like Multiplay. To do this effectively, you'd need the matchmaking to orchestrate instances running.

#

Usually, it's fine to start with Fusion's "Host Mode". Then some client is running a client plus a "Fusion server".

stiff ridge
civic flicker
#

since i want the game to be online as well, and not only local

#

how hard is it to implement a simple system?

stiff ridge
stiff ridge
civic flicker
civic flicker
#

if i had relay on my game, the process to have it accepted on steam would be easier?

stiff ridge
#

I don't know about Steam's publishing requirements. I don't think it matters.

civic flicker
#

okay then, ill check on the NAT punch through topic

#

thank you for the info!

heady locust
# stiff ridge It depends. We run Photon Servers on the Photon Cloud for everyone to use. If yo...

Hey @stiff ridge
Thank you for reply.

We run Photon Servers on the Photon Cloud for everyone to use. If you don't need to customize this, you can use it.
This part is not clear to me.
As I know the Photon Cloud is kind of relay, it handles matchmaking, and data transfers to the users.
Photon Server is something that we can run on our local host and test the games, or we can put it on some hosting (non gaming hosting) and run our game on that custom host.

The Photon Servers run a lot of rooms each (but don't run Unity itself).
You mean each photon server can run several rooms on the same instance of the game? I don't understand the server scaling part.

You usually don't run Photon Servers on services like Multiplay but you'd run those on baremetal machines.
I also know so, that the Photon Server is for creating custom host on users PC.
That is why I can not understand your first sentence.

With Fusion, you could build a Unity instance as Server and run that per session/game-instance on services like Multiplay. To do this effectively, you'd need the matchmaking to orchestrate instances running.
So if I build a Unity Server instance and put it on let say Unity Game service or Multiply, each room will create an instance of the game on the host side?
If so then
1. one server multiple instances?
2. or one server per instance?

I know I miss some important things, that is why I ask those question to put all together.
Thanks.

weak plinth
#

For the unity multiplayer (Unity Relay), what happens if the free tiers are used and you have to start paying

#

Will unity inform you

#

Or will it just take money

#

Is there a way, when it will cost too much, and if it goes over the free tiers, the servers would stop.

austere yacht
austere yacht
austere yacht
#

I recommend checking your daily usage reports diligently

#

first feature you should implement in all your servers is automated shutdown on a timer

summer anchor
#

Just wondering if im handling everything correctly in my co op fps game.

For shooting i use this
-player casts a raycast, and sends the raycasts hit and the players name who shot it to a command
the command has a deal damage function to the player hit by the raycast. then also sends an rpc with the players name that shot and called the command.
clientrpc checks who the player is, then runs the shoot function only on that player (animations, sounds etc)

Am i running everything correctly? or will i get issues because the player wont actually see he is shooting until the server tells him he is, it seems pretty instant to me just curious if its right or not, thanks

stiff ridge
# heady locust Hey <@88211688288956416> Thank you for reply. > We run Photon Servers on the Ph...

The Photon Server is the basis for the Photon Cloud and the Photon Server SDK. It runs a base logic to distribute games across regions and then games across a number of "Game Servers", which enables us/you to scale for number of rooms running. In rooms, clients can send messages to others, store properties on the server, etc. This is called the Realtime API.
The Photon Cloud runs this logic "as is" in a default configuration. You can get the Photon Server software and run it "as is" if you like. With the SDK you can also modify it.
If needs be, you could write your own game logic with this. It is run "per room". Only one Photon Server instance is needed to run a large number of rooms and it could have some game logic. However, you can't run a Unity instance in those rooms (so no physics, etc). This is best for turn based game or games where the simulation can run without Unity (no physics, etc). Then this is very effective.

Fusion Servers are Unity instances. They should be run per match and it supports physical interactions, using the scene, navigation, etc.
Each Fusion match needs a host or server (unless you use the Shared Mode) and you could run those on any of the Unity hosting services (Photon won't host and run those instances, it just coordinates them and provides deep networking integration via Fusion).
You can run multiple instances on a single physical machine (actually, the more run per machine, the better, as this is more cost effective)...

heady locust
civic flicker
#

why is it everytime i make a new build i always have to make the animation discrete again?

#

it always goes back to disabled after the build

spring crane
civic flicker
#

if i instantiate another player prefab it goes back to disabled

#

maybe i should force it to be discrete through a script

severe fable
#

How can I send a struct with a client connection attempt? Here is an example which I think should work, but doesn't. I have a really simple struct (just 2 strings). I'm then serializing to byte[] and putting into the clients ConnectionData. However the connection just silently fails (the host never gets the connection attempt). If I remove the ConnectionData then the attempt does go through.

brittle gyro
#

Does anyone have a good list of structs example for synchronizing data between server and client in NetcodeForGameobjects? I'm making a player preferences object which includes a list of player icons that persist between scenes.

fair berry
#

Am i doing something wrong?

fair berry
#

okay nvm im stupid

brittle gyro
fair berry
#

ohh nice

severe fable
#

You just have to make sure the struct extends INetworkSerializable, IEquatable

#

Example of a struct which can be put into NetworkList: ```cs
using System;
using Unity.Netcode;

namespace Structs
{

public struct ClientPing : INetworkSerializable, IEquatable<ClientPing>
{
    public ulong clientId;
    public double ping;

    public ClientPing(ulong _clientId, double _ping)
    {
        clientId = _clientId;
        ping = _ping;
    }

    public bool Equals(ClientPing other)
    {
        return clientId == other.clientId;
    }

    public override bool Equals(object obj)
    {
        return obj is ClientPing other && Equals(other);
    }

    public override int GetHashCode()
    {
        return HashCode.Combine(clientId);
    }

    public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
    {
        if (serializer.IsReader)
        {
            var reader = serializer.GetFastBufferReader();
            reader.ReadValueSafe(out clientId);
            reader.ReadValueSafe(out ping);
        }
        else
        {
            var writer = serializer.GetFastBufferWriter();
            writer.WriteValueSafe(clientId);
            writer.WriteValueSafe(ping);
        }
    }
}

}

brittle gyro
#

Is there any way to guarantee one OnNetworkSpawn will be triggered before another?

#

Thinking of just chaining listeners, but would be nice to know if there's a way to guarantee order

#

Like a priority indicator or something

remote mulch
#

Hey any idea why on my photos server when the game is built I can make and join a server but upon leaving the servers I make or my friend makes doesn't show up until I rebuild the entire game and send it to him again,if you require my code I don't have it rn as I'm on phone but I'm using the photon basics I copied off the net

weak plinth
#

New Unity multiplayer is so cool

gusty fjord
#

Netcode for Gameobjects: I was assuming Instantiating a GameObject on the server, setting variables and then Spawning the NetworkObject would sync the variables I set before spawning to clients. It appears it doesn't, correct? Is the only way for me to do this to use NetworkVariables for this data instead? Is it guaranteed that the NetworkVariables will be synced before OnNetworkSpawn is called on the newly Spawned GameObject's NetworkBehaviours, or do I need to listen to value changes? The data I set is not supposed to change after the server set it up before Spawn.

pure acorn
#

Anyone good with reading player.log files to help me understand a crash

severe fable
# gusty fjord Netcode for Gameobjects: I was assuming Instantiating a GameObject on the server...

Only NetworkVariables will be synced automatically. I could be wrong but I don't think you can assume NetworkVariables will be synced at the time of OnNetworkspawn. If you start a host, change the some networkvariable, then join a client. The client might have the initial value at OnNetworkSpawn (not yet have the synced value). So if you want to do something at Start on the client you should run it both as a function in OnNetworkSpawn and then also run it again as a value change listener on the networkvariable.

#

Example: ```cs
public override void OnNetworkSpawn()
{
DoAThing();
TheNetworkVariable.OnValueChanged += (value, newValue) => DoAThing();
}

gusty fjord
#

Thanks!

severe fable
#

That way you are covered no matter what order the syncing happens in

#

Does anyone know of a way to listen for the NetworkManager.Singleton.StartClient(); successful connected? Currently I'm listening to OnTransportEvent, but this is pretty poor way to do it. As "connected" event gets triggered even if the Host rejects the connection at approval

spring crane
#

Link to Photon discord is in the pinned message.

tight basin
#

Thanks, I have removed my message.

stiff ridge
boreal willow
#

hello, anyone know how to spawn player after a scene loads? with newest networkmanager for netcode

subtle gate
#

hi i wanna transfer data between two clients in photon

#

its my ui i just want that when i wrote msg in txt field and send it.its easily shown to all clients

#

i scrollbar i am using prefebs which are instantiated

fierce moth
#

i made this launcher code for photon pun

#

it said loaderanime

#

and i see this

#

anyone please help

olive vessel
#

There is a Demo from PUN called Launcher, you have applied that to an object

#

It does have loaderAnime

#

But your script is not Launcher, you misspelt it

#

So you think you added your script, when in actuality you added the demo script which you don't want

fierce moth
#

my friend cant play with me we cant connect to the server

#

he can make a server but i cant join

#

but in my pc i opened 2 clients and started server in one of them and i can join from other client

frozen summit
#

Howdy! ik there's like 20 different solutions for multiplayer.. Idk how to choose.
I am just making a 2d platformer rocket league-like game lol
so i really just need to keep track of the two players..

#

if anyone has any suggestions for a small game, plz lmk. just trynna make this for me and a friend to play (not locally). no lobbies or anything else complex

hearty dock
# boreal willow BUMP

just put the code to spawn the player in Start, in a script that's in the newly loaded scene

boreal willow
hearty dock
#

So have the script spawn the object when the player presses a button instead

#

what's the difficulty

boreal willow
#

but the scene isnt loaded yet when they press the button

hearty dock
#

you're being very unclear about the setup/what you're trying to do

boreal willow
#
hostBtn.onClick.AddListener(() =>
        {
            SceneManager.LoadScene("Game");
            NetworkManager.Singleton.StartHost();
        });

I have something like this, it's in the menu scene and I need it to load a game scene and start hosting the game, but the problem is that it spawns the player before the scene is finished loading

#

@hearty dock

hearty dock
#

you need to wait until the next frame

boreal willow
#

so, I should do a coroutine for this?

hearty dock
#

that's one way to wait a frame, sure

#

Realistically you should use asynchronous scene loading

sand hornet
#

I am getting this error in mirror where it says "Not possible to Convert type "ulong" in "string" "

frozen summit
little sorrel
#

How do I use gameobject.find for only objects I have ownership over in PUN 2

wide girder
little sorrel
wide girder
#

That would only find the first object with that name. You want to use the plural find functions.

little sorrel
wide girder
#

No

little sorrel
#

and thenhow do I filter by ownership

wide girder
#

For or foreach loop, get the view component and check if it belongs to the client.

little sorrel
wide girder
#

I'd note though, that you should probably cache your components instead of finding them at runtime.

little sorrel
#

this doesn't work

wide girder
#

Ughh... It's assumed that you are at least intermediate+ level coder if you're doing networking, so you should know that...😬

wide girder
little sorrel
wide girder
#

That screenshot doesn't explain what doesn't work.😅

little sorrel
wide girder
#

In what sense does it not work?

little sorrel
#
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class MoveCamera : MonoBehaviourPunCallbacks
{
    public PhotonView pv;
    private GameObject player;

    void Update()
    {
        if(pv.IsMine){
            Camera.main.transform.position = new Vector3(player.transform.position.x, player.transform.position.y, Camera.main.transform.position.z);
        }

    }
}
wide girder
#

player is not assigned.

#

You only assign pv in the inspector.

little sorrel
#

OH MY GOSH

#

I'm dumb

woven kiln
#

Does anyone has experience with Unity Transport? How does it compare to other networking solutions?

#

For massive multiplayer games. Can it handle the load?

green moat
#

hey networking folks, do you have any idea how to make a simple patcher for my multiplayer game? I mean, the game should check the game version by start and if it doesn't match, download something

wide girder
spring crane
green moat
green moat
wide girder
#

There's no unity docs for that. It's mostly work outside of unity. The only relevant unity part is perhaps the WebRequest API if you choose to use it instead of your own solution.

wide girder
woven kiln
#

here on BeginSend i need to rebuild the buffer every time

#

Same for snapshot interpolation. It is ideal to compute the buffer 1 time and broadcast it to all peers

meager abyss
#

does anyone know how to make SignalR work with unity ?

I want a normal C# app to be the server

(or if you know something better you can tell me)
I basically want players to be able to communicate with the server and the server to know when a player looses connection

meager abyss
civic flicker
#

it'll automatically create port forwarding for you, and there's in built functions that'll do what you want

meager abyss
#

Thank you! I’ll try it later today

cerulean salmon
#

hey im not that good at c# and i would love some help i looked on some tutorials on how to make a lobby for a game im working on its based on NetCode and i cant find how to fix the error. Any helps would be thanked🙏

civic flicker
#

that name doesnt exist in NetworkManager

cerulean salmon
#

It does tho that is what i dont understand

civic flicker
#

yea im trying to figure it out too

civic flicker
#

ah

#

its NetworkBehaviour

#

not MonoBehaviour

#

you have to inherit from NetworkBehaviour instead

cerulean salmon
#

But its passwordnetwork behaviour

civic flicker
#

thats the name of your script

cerulean salmon
#

Ohh

#

Ye

#

Got it

civic flicker
#

switch MonoBehaviour for NetworkBehaviour

cerulean salmon
#

And thats it?

civic flicker
#

it also inherits the MonoBehaviour classes so dont worry

#

i think so

#

give it a try

cerulean salmon
#

Thank you

#

Ye i will thanks

#

still didnt work

#

same error

#

got any other ideas?

spark violet
#

hey guys what would u advice if i wanna create multiplayer for like 2-4 players not setting up servers etc or w/e just them all connection to one players client what way is best? any tutorials you would recommend or tools ?

#

@cerulean salmon

civic flicker
#

did it give you a different error?

spark violet
#

@civic flicker

cerulean salmon
cerulean salmon
civic flicker
#

use photon

civic flicker
#

you said youre following a tutorial

#

maybe he did something you forgot to do?

olive vessel
#

I would take care watching any old "MLAPI" tutorials, Netcode for GameObjects has changed a fair amount

#

As you can see here, the name has changed

maiden bobcat
#

Hello guys how are you all doing? I am making an app in Unity where I have a list of all characters from the mixamo website in the app in a scroll view and each item s the character image and its name, I finished all the design but now I need to get the characters and I dont have a lot of experience in this field all I know is I need to get a request and then maybe look in the HTML code of the characters and get each one's image and name but idk how to do that can anyone help?

cerulean salmon
civic flicker
cerulean salmon
#

ok

#

thanks

#

so i need to change the NetworkManager.connectionAprrovedDelegate?

civic flicker
#

honestly i also used Netcode for GameObjects and it was a complete mess just to do simple stuff like synchronizing the players

#

i switched to photon and had it set up in 1 hour

cerulean salmon
#

idk really how to setup a multiplayer thing

#

thats why i followed a tutorial

cerulean salmon
#

bro i just saw this video b4 u sent me it

#

thx tho

#

i will use this instead

sand hornet
#

Is the new unity multiplayer netcode good? For using with steam and p2p

woeful shale
#

Hi guys, I'm having problems with the UI of my game. The weird thing is that the UI updates when I play the single player part of the game, but in the multiplayer section when 2 players are in the room, the UI doesn't update anymore. Please help.

fervent pebble
#

and does it work normally as long as there is just one player in the room but still connected to the network?

woeful shale
fervent pebble
woeful shale
fervent pebble
#

And who is it pointing at when you have 2 players

woeful shale
#

I'm trying to get the console logs coming from the other build, to see. But local is getting the right one.

woeful shale
#

I debug, the health values, and is not refreshing, it's like the player isn't doing any damage

fervent pebble
woeful shale
woeful shale
woeful shale
misty gulch
#

is it possible to call a Coroutine as a server RPC? (Unity networking for gameobjects)

spring crane
#

You certainly can as a result of an RPC

misty gulch
# spring crane You certainly can as a result of an RPC

Thats what i get:
Error: ```(0,0): error - RPC method must return void!````
Code:

void start(){
  StartCoroutine(FootstepGenServerRpc());
}
[ServerRpc]
    private IEnumerator FootstepGenServerRpc(){
        begin:
        for( ;steping; ){
            GameObject step = Instantiate(Footsteps,new Vector3(transform.position.x, transform.position.y, 121f), transform.rotation);
            step.GetComponent<NetworkObject>().Spawn();
            yield return new WaitForSeconds(.3f);
            if(!steping) break;
            step = Instantiate(Footsteps2, new Vector3(transform.position.x, transform.position.y, 121f), transform.rotation);
            step.GetComponent<NetworkObject>().Spawn();
            yield return new WaitForSeconds(.3f);
        }
        if(!steping){
            yield return new WaitForSeconds(.3f);
            goto begin;
        }
    }
spring crane
#

Have a separate RPC method that does whatever you want with the coroutine

misty gulch
#

Do you mean something like this?

void Start(){
  FootstepGenServerRpc();
}
[ServerRpc]
    private void FootstepGenServerRpc(){
        begin:
        for( ;steping; ){
            GameObject step = Instantiate(Footsteps,new Vector3(transform.position.x, transform.position.y, 121f), transform.rotation);
            step.GetComponent<NetworkObject>().Spawn();
            StartCoroutine(WaitServerRpc());
            if(!steping) break;
            step = Instantiate(Footsteps2, new Vector3(transform.position.x, transform.position.y, 121f), transform.rotation);
            step.GetComponent<NetworkObject>().Spawn();
            StartCoroutine(WaitServerRpc());
        }
        if(!steping){
            StartCoroutine(WaitServerRpc());
            goto begin;
        }
    }

    [ServerRpc]
    private IEnumerator WaitServerRpc(){
            yield return new WaitForSeconds(.3f);
    }
spring crane
misty gulch
spring crane
misty gulch
#

i need to spawn footsteps for all the players running around the world and because clients cant spawn network prefabs i need the server to spawn them. Now, in the footsteps function i need to wait between those steps .3 secs until i spawn the next. thats why i would need a coroutine

full girder
#

what are the current networking solutions that unity has? I haven't kept up on Unity in a while

spring crane
full girder
spring crane
#

Check the pinned message. Yea you'll still likely find thirdparty stuff superior for most projects.

#

Photon has cool new products

woeful shale
#

So I got an issue right now. I'm instantiating 2 players into a room, both have the same health scripts. But if I Debug.Log(this.gameobject.name), is printing the name of the other player instead of his. Is there a way to prevent this?

delicate inlet
#

Im Makeing a project online multiplayer and it gives the following error when I'm done writing the ui code (its useing network manager)

#

Here is the code aswell

#

Anyhelp much appreciated

spring crane
frozen summit
#

So this code works for first person who joins, when second person joins.
But it doesn't show first person's color to the second person that joins.

photonView.RPC("SetColor", RpcTarget.All, new Vector3(setColor.r, setColor.g, setColor.b));

[PunRPC]
private void SetColor(Vector3 setColorVector)
{
    Color setColor = new Color(setColorVector.x, setColorVector.y, setColorVector.z);
    GetComponent<SpriteRenderer>().color = setColor;
}

any suggestions? 🤔

woeful shale
#

By printing it, it takes the other player object name instead of his own object name

spring crane
spring crane
woeful shale
spring crane
woeful shale
fervent pebble
#

hey, I struggle to flip the character sprite on guest clients. I have followed the tutorial of Photon, which I use, but it wont do it
https://gdl.space/mijoyuceri.cpp

spring crane
#

This allows you to highlight the source of the log by clicking on it

woeful shale
spring crane
woeful shale
spring crane
frozen summit
# spring crane Sounds like the information is just not synced to new players. Send the colors t...

The whole issue ive been having is passing variables between clients..
Seems like every new instance erase all previous data and re-initializes variables.

I am even trying to do

        PhotonNetwork.LocalPlayer.CustomProperties["go"] = newPlayer;
        PhotonNetwork.LocalPlayer.CustomProperties["color"] = color;
``` when i create player

and i set colors when new player joins
```csharp
        foreach (var player in PhotonNetwork.PlayerList)
        {
            GameObject go = (GameObject) player.CustomProperties["go"];
            go.GetComponent<SpriteRenderer>().color = (Color) player.CustomProperties["color"];
        }
```but it says `go` does not exist
spring crane
# frozen summit The whole issue ive been having is passing variables between clients.. Seems li...

Seems like every new instance erase all previous data and re-initializes variables.
Clients don't have any data that isn't sent to them through some means. Also make sure you aren't confusing properties of one player with properties with some other player.

Storing gameobject references in custom properties doesn't seem right. You probably need to sync the photonView viewId and convert to gameobject yourself for this to work.

frozen summit
#

i thought photonnetwork would contain data from other clients and be able to transfer them to new ones

#

i'd imagine that's how multiplayer works in general

#

and ig i just assumed there was an easy way to do it

spring crane
#

Don't assume that anything is transferred until you know about a feature that does it.

#

Multiplayer solutions can't really guess what state needs to be transferred

woeful shale
#

Yes, both highlight different gameobjects

#

Now only one updates the health value, the other not, and both have to decrease their values when colliding

#

Only one does it.

frozen summit
spring crane
woeful shale
serene saddle
#

Do y'all support Photon dev here

wide girder
#

We don't support "Photon dev" here.

#

Jk

#

If it's unity related, then ask away.

summer anchor
#

what is better, mirror or netcode?

wide girder
#

What is better, cats or dogs?

summer anchor
#

😂

#

well im super new to unity, been using mirror, just starting a new project and wondering the netcode has any benefits to it?

wide girder
shell nest
#

(Photon) How can I synchronize text and inputfield text across clients? RPC?

dusky storm
oblique herald
#

trying to make a mp game but already having problems with fizzysteamworks 😄

amber pilot
#

In unreal engine, There is replication for multiplayer, But in unity, Which method is officially used for multiplayer?

olive vessel
#

Netcode for GameObjects is the official Unity multiplayer package

#

There are other solutions like Mirror and Photon (PUN, Fusion)

oblique herald
#

Welsh do you know why fizzy steamworks doesnt work?

#

Watching a tutorial on how to set it up and all they did was import mirror and fizzysteamnetworks but i did and got 2 errors

amber pilot
olive vessel
amber pilot
#

which method is most popular in other words

olive vessel
#

Popularity ought to be irrelevant

#

You pick the solution that works for you

#

I personally found Mirror to be very intuitive, and it has all the features I wanted

amber pilot
#

ok thanks!

shell nest
austere yacht
shell nest
#

same for text.

austere yacht
#

and how is it not obvious how to implement that?

shell nest
#

why would it be?

#

I know almost nothing about Photon.

#

Should I use an ExitGames.Client.Photon.Hashtable?

austere yacht
shell nest
#

Why would an implementation be obvious though?

austere yacht
shell nest
#

what

olive vessel
#

Have you tried looking up how to synchronise data between clients?

shell nest
#

yes

olive vessel
#

So why didn't that help?

digital compass
#

I'm using Unity's networking system and I have a problem where when I spawn in a client, the mouse position gets really offset. I'm trying to spawn a gameobject at the mouse, but the object is sometimes nowhere near the mouse, always at least a bit away from it

shell nest
#

because I didn't comprehend it.

austere yacht
shell nest
#

yes

#

that's why I asked if I should use a hashtable or an rpc or something like that.

austere yacht
shell nest
#

no

olive vessel
#

I don't get why a Hashtable is useful here

shell nest
#

I don't know.

#

that's why I'm asking you.

olive vessel
#

Right so use the other option you discovered

#

RPCs are designed to sync information

shell nest
#

rpc?

#

ye

austere yacht
#

sounds like you are asking random unrelated questions

olive vessel
#

It's their purpose

shell nest
#

but I haven't got them to work.

#

that well lol.

olive vessel
#

So what issues have you had with RPCs?

shell nest
#

not getting them to work obviously.

austere yacht
olive vessel
shell nest
#

I don't really know how to use them.

haughty heart
#

You just mistyped RPC in your code, that's all.

shell nest
#

what

#

mistyped?

haughty heart
#

Yep

shell nest
#

is it possible to call rpcs in other classes?

olive vessel
#

They're just methods

haughty heart
#

Because not getting it to work, obviously was exactly enough info to solve your issue.

shell nest
#

yes but you have to call them with a string, right?

olive vessel
#

Right so make a method that calls the RPC, and call that method instead

shell nest
#

right stupid me

#

Don't I have to do something like this too?

#

I'm confused. ```cs
PhotonView view;

void Start()
{
    view = GetComponent<PhotonView>();
    view.RPC("RPC_SetText", RpcTarget.AllBuffered, dict.randomLetterText);
}

[PunRPC]
void RPC_SetText(TMP_Text text)
{
    text.text = text.text;
}
#

please don't call me even more stupid.

#

I know.

#

I wanna set more text strings than that though.

olive vessel
#

I wouldn't sync the actual Text component

shell nest
#

no?

olive vessel
#

No

shell nest
#

I'm syncing the text of it though.

olive vessel
#

You send the component in an RPC, can Photon even do that?

shell nest
#

text.text = text.text sounds like saying string foo = foo;

olive vessel
#

Lets say I type a message in a chat, what do you think happens

#

Like here in Discord

shell nest
#

internal static void RPC(PhotonView view, string methodName, RpcTarget target, bool encrypt, params object[] parameters)

#

idk

olive vessel
#

Engage your brain, this is an easy question

#

In simple terms, what does this chat menu do

shell nest
#

it gets sent to you via their servers?

shell nest
olive vessel
#

What does it send?

shell nest
#

data

olive vessel
#

It doesn't send my text field

shell nest
#

lol

olive vessel
#

It sends my message, the string I type

shell nest
#

yeah

#

but it has to implicitly know which text field I'm talking about, right?

olive vessel
#

Every client has this script, which references their own input field

shell nest
#

the text is random though.

#

and input fields don't just automatically sync.

olive vessel
#

So a client sends one of those to every other client?

shell nest
#

not yet.

#

that's what I want to happen.

olive vessel
#

Right

#

So what's the issue with sending a string using an RPC?

#

You don't need to send over the text object

#

My instance of the script in my client references my text field, not yours

#

So when you RPC me a string, it will set my text field

shell nest
#

you're saying that I have to make a function for every single text field?

olive vessel
#

No, I have no idea what the structure of your game is

shell nest
#

it's a word game.

#

online

olive vessel
#

I mean technically most games involve words, so that's a largely unhelpful description

shell nest
#

you have to come up with words.

#

that contain a set of random letters.

#

not come up with, enter.

olive vessel
#

So you give me letters, I make them into a word

shell nest
#

it has to contain "ab" in this case.

olive vessel
#

Right

shell nest
#

yes

#

a word that exists.

olive vessel
#

So the host sends everyone a string "EG" or something

#

Then they can all send back their string "Egg"

shell nest
#

yeah if you're talking about the input field.

olive vessel
#

So you want an RPC to send everyone the random letters, literally just send them a string

shell nest
#

example:

#

then when you press enter, they get randomized.

shell nest
olive vessel
#

No

shell nest
#

I mean text input thing.

#

what then?

olive vessel
#

Are you suggesting every client needs their own RPC to send the data?

shell nest
#

I guess.

olive vessel
#

Well they don't, there's probably some ID you can send with their answer

shell nest
#

answer, as in word?

#

or what

#

how would I use an id?

olive vessel
#

Answer as in the thing they typed yes

#

Well I don't know PUN, but I assume you have a way of identifying clients

#

Name, number idk

shell nest
#

oh ye

#

Wouldn't this work? ```cs
void Start()
{
view = GetComponent<PhotonView>();
view.RPC("RPC_SetText", RpcTarget.AllBuffered, dict.randomLetterText.text);
}

[PunRPC]
void RPC_SetText(string text)
{
    dict.randomLetterText.text = text;
}
#

if I were to call the function somewhere else (rpc).

#

whenever the random letters are updated for instance.

olive vessel
#

I assume that this code would sync whatever is typed in that field to all clients at the Start

shell nest
#

ye

#

but if I were to change that, as I said.

olive vessel
#

Sure, give it a go

shell nest
#

something like this: ```cs
public void CallRPC(TMP_Text textField, string text)
{
view.RPC("RPC_SetText", RpcTarget.AllBuffered, textField, text);
}

[PunRPC]
void RPC_SetText(TMP_Text textField, string text)
{
    textField.text = text;
}
olive vessel
#

Why are you sending the text field?

#

You don't even use the reference you send

shell nest
#

for implicitness.

olive vessel
#

I think you ought to get a dictionary and define that word

#

Because if it were even a good idea to send the text object, it'd be for explicitness

shell nest
#

I can't figure out how exactly the script is supposed to know what text field I'm talking about.

olive vessel
#

The script has a reference to a text field right?

shell nest
#

no

#

I don't wanna create multiple functions.

olive vessel
#

I give up

#

I am trying really hard here, and I'm getting sod all

shell nest
#

should I?

olive vessel
#

No for fucks sake

shell nest
#

then what?

#

let's say that I were to have multiple text fields.

#

how would the script know which one I'm talking about?

#

if the only parameter was a string.

olive vessel
#

Give me a few minutes

shell nest
#

for sanity?

#

lol

olive vessel
#

It's too early for gin, I'm writing an example instead

shell nest
#

oh ok thanks.

olive vessel
#
public class RandomLettersOrSomeShitIdfk
{
    public TMP_Text randomLetterText; //Set this in the inspector
    
    public void CallRPC(string text) //Method to call this RPC from other classes
    {
        view.RPC("RPC_SendRandomLetter", RpcTarget.AllBuffered, text); //RPC call
    }
    
    [PunRPC]
    private void RPC_SendRandomLetter(string text) //When this is called, every client will receive this RPC
    {
        randomLetterText.text = text; //This will set the client's individual text field to this text
    }
}
#

This script will exist on all clients, there will be a Text object on all clients that this script refers to

shell nest
olive vessel
#

So each client has how many text fields?

shell nest
olive vessel
#

Two

shell nest
#

yes

#

two functions.

olive vessel
#

Well that's expected surely, those fields do different things

shell nest
olive vessel
#

You are testing me

shell nest
#

not really

olive vessel
#

Oh you fucking are

#

You know full well you haven't been crystal clear, so I won't apologise for making a mistake

shell nest
#

everyone makes mistakes.

#

it's fine.

haughty heart
#

@shell nest This person is taking the time to talk to you, stop being insufferable.

#

@olive vessel This is probably a time to take a break and leave it, it's not worth the annoyance.

serene saddle
#

Alright, so I'm working on the Multiplayer aspect of my game now through Photon. I have a 'NetworkController' script attached to a GameObject which has something along the lines of this in it..

OnConnectedToMaster() {
   PhotonNetwork.JoinOrCreateRoom("Test", roomOptions, TypedLobby.Default)
}

OnPlayerEnteredRoom(Player newPlayer) {
   PhotonNetwork.Instantiate("player-blue", gameController.transform.position, gameController.transform.rotation);
}

The player-blue prefab has a PhotonView attached to it, with a PhotonTransformView attached aswell. But when two players join, it creates the Prefab but it doesn't seem to be syncing the positions.

It's very possible I'm doing this wrong. Any help greatly appreciated.

serene saddle
#

My 'Player' prefab (screenshot above) contains all of the scripting.

civic flicker
#
public class Attack : MonoBehaviour
{
    [SerializeField] private bool isAttacked;
    [SerializeField] private Slider playerHP;
    [SerializeField] private int damage;
    [SerializeField] private PlayerMovement playerMovement;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (isAttacked && playerMovement.view.IsMine)
        {
            playerHP.value = playerHP.value - damage;
            isAttacked = false;
        }
    }

    public void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            isAttacked = true;
            playerHP = other.GetComponentInChildren<Slider>();
        }
    }

    public void OnTriggerExit2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            isAttacked = false;
        }
    }

Hallo, how can i identify only a single player (the one that is being attacked)?

misty gulch
#

How do i make an string Network variable? Every solution from the documentation is outdated or doesnt work. (using Networking for Gameobjects)

misty gulch
#

thats the problem. idk which namespace i need to include to use Fixed private StringContainer m_StringContainer = new StringContainer(); or private NetworkVariable<FixedString128Bytes> m_TextString = new NetworkVariable<FixedString128Bytes>();

olive vessel
#

Unity.Collections

#

Just Google the type

misty gulch
misty gulch
#

also, how do i pass a param to an Server RPC method? i get an mega error when i try

public class Weapon_Destroy : NetworkBehaviour
{
    public GameObject player, PickedUp;
    private Inventory_Handler inv_handler;
    // Start is called before the first frame update
    private void OnTriggerEnter2D(Collider2D collision){
        if(IsOwner){
            DestroyWeaponServerRpc(collision);
        }
    }

    [ServerRpc]
    private void DestroyWeaponServerRpc(Collider2D collision){
        if(collision.gameObject.tag == "Player" && collision.GetComponent<Inventory_Handler>().lootcount < 3 || collision.gameObject.tag == "Bot" && collision.GetComponent<Bot_Inventory>().lootcount < 3){
            Destroy(this.gameObject);
            gameObject.GetComponent<NetworkObject>().Despawn();
        }
    }
}

Error:
Don't know how to serialize Collider2D. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace UnityEngine.Collider2D with ForceNetworkSerializeByMemcpy`1<UnityEngine.Collider2D>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out UnityEngine.Collider2D) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in UnityEngine.Collider2D) to define serialization for this type.

olive vessel
#

I don't think there's a built in serialiser for a Collider2D

#

Maybe try finding a way of passing what you want rather than the entire thing

austere yacht
misty gulch
serene saddle
civic flicker
serene saddle
#

I actually am as far as I'm aware. if(!photonView.IsMine && PhotonNetwork.IsConnected) { return; } is on any move request pretty much.

civic flicker
#

it helps setting up a lobby + characters

opaque ember
#

can someone help me with photon?

#

I wanted developer cosmetics for my game

summer anchor
#

my player movement has stopped syncing. i have network transform with client auth, rotation and position ticked. it is syncing rotation just not position for the clients, any ideas why?

patent fog
summer anchor
#

Not that i can think of. its a pretty fresh project, just has player movement, and weapon switching, the weapon switching is just a syncvar hook that enables / disables the child objects

#

host can see both players moving / switching weapons. the client cant see the host moving, only rotating and changing weapons

civic flicker
#
public class Attack : MonoBehaviour
{
    [SerializeField] private bool isAttacked;
    [SerializeField] private Slider playerHP;
    [SerializeField] private int damage;
    [SerializeField] private PlayerMovement playerMovement;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (isAttacked)
        {
            playerHP.value = playerHP.value - damage;
            isAttacked = false;
        }
    }

    public void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            isAttacked = true;
            playerHP = other.gameObject.GetComponentInChildren<Slider>();
            playerMovement = other.GetComponent<PlayerMovement>();
        }
    }

    public void OnTriggerExit2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            isAttacked = false;
        }
    }
}

i want to have my enemy attack a player and make him lose HP, while the other one still has full HP. my problem is that for some reason the one that is being attacked is not the one losing hp, and vice versa. (im using photon)

terse idol
#

Hi, how can I fix this error?

spring crane
civic flicker
#

i just learned about RPCs

#

the enemy is removing HP from my players

#

but whats weird is

#

if it attacks player 1 it removes hp from player 2 and vice versa

serene saddle
#

So I might of been overthinking my project's instantiation.

I have a 'PlayerPrefab' which hosts the camera, movement, controllers etc and I have an actual character inside that Prefab which has a PhotonView & PhotonTransformView attached to it.

When I start the game, I have set up to automatically join or create a room, and Instantiate the character (which has the photon views) and parent that to my PlayerPrefab.

When another person joins, I see their character but their position is not synced at all and I'm unsure why

#

Under that inactive capsule is where the first character (me) would load in.

oblique herald
#

why dont these glasses sync up but the movement etc does it?

#

Is it cause of this ?

#

i got if (hasAuthority)

oblique herald
#

Isn’t if (hasAuthorityk) to see if it’s the client so it will only do it for the client ?

#

But then that’s weird cause I have my movement func inside a if (hasAuthority) but that replicates, Is it cause the player is a network transform ?

civic flicker
oblique herald
#

umm just a question, Ill send a video of my animations, They do not work online, And when i am in the scene view at game view, In the game it looks as it should but in the scene view it looks well kinda weird

#

Or wait, No

#

When i come into a certain radius of the player it starts animating

#

tf

#

Think i found it

serene saddle
#

I managed to get player positioning, rotationing & animations synced. On any object that I want to have clickable, I have a 'void Click()' function within the script attached to that object. Click() is called by a Raycaster on my PlayerController which checks to ensure that what I'm looking at isn't null and is within a distance of < 2.5m. What is the easiest way that I can simulate a click across all clients?

serene saddle
#

GetComponentInChildren<PhotonView>().RPC("ClickObject", RpcTarget.All, hit.transform.gameObject); is something I tried but it's complaining saying GameObject doesn't exist.

flint cove
flint cove
serene saddle
#

Okay, it turns out you can't pass objects over through Rpc, fair enough - so my solution was to pass over the Vector3 and do a very small Physics.OverlapSphere() on the hit.point of my ray cast to send a message to objects.

Well now that's gotten me the error message:
RPC method 'ClickObject(Vector3)' not found on object with PhotonView 1001. Implement as non-static. Apply [PunRPC]. Components on children are not found. Return type must be void or IEnumerator (if you enable RunRpcCoroutines). RPCs are a one-way message.

With this code:

    [PunRPC]
    void OnClick()
    {
        RaycastHit hit;

        if(Camera.main)
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform != null && hit.distance <= 2.5f)
                {
                   // ClickObject(hit.point);
                   GetComponentInChildren<PhotonView>().RPC("ClickObject", RpcTarget.All, hit.point);
                }
            }
        }
    }

    [PunRPC]
    public void ClickObject(Vector3 objTransform)
    {
        RaycastHit hit;
        Collider[] x = Physics.OverlapSphere(objTransform, 0.1f);
        foreach(Collider c in x)
        {
            c.SendMessage("Click", SendMessageOptions.DontRequireReceiver);
        }
        // objTransform.SendMessage("Click", SendMessageOptions.DontRequireReceiver);
    }

The PhotonView prefab itself is childed to where this script is being run.

shell nest
austere yacht
spring crane
misty gulch
#

So I thought about solving this problem without serializing a whole gameObject to pass it to the Server Rpc method. But there comes no other way to my mind when i think about destroying a NetworkPrefab in the scene.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;

public class Weapon_Destroy : NetworkBehaviour
{
    public GameObject player, PickedUp;
    private Inventory_Handler inv_handler;

    private void OnTriggerEnter2D(Collider2D collision){
        if(IsOwner){
            DestroyWeaponServerRpc(collision.gameObject);
        }
    }

    [ServerRpc]
    private void DestroyWeaponServerRpc(GameObject collision){
        if(collision.gameObject.tag == "Player" && collision.GetComponent<Inventory_Handler>().lootcount < 3 || collision.gameObject.tag == "Bot" && collision.GetComponent<Bot_Inventory>().lootcount < 3){
            Destroy(this.gameObject);
            gameObject.GetComponent<NetworkObject>().Despawn();
        }
    }
}

Do you have any ideas how to either serialize the whole GameObject or have another way to reference to the to be destroyed gameObject?

austere yacht
#

a good multiplayer design eliminates unnecessary messages/arguments wherever it can

misty gulch
austere yacht
misty gulch
austere yacht
misty gulch
#

pls tell me i ll figure it out

austere yacht
#

there is nothing to figure out, its just a long journey digging through all the crappy solutions and workarounds you have to create, fix endless bugs and issues and realize that it took you about 5 times longer than rewriting the whole thing

misty gulch
#

ok lets say i rewrite it, what would i change to destroy that gameobject with an server rpc

#

actually i am rewriting it rn more or less

patent fog
#

You would work with IDs so you don't have to serialize whole gameobjects

#

Client sends ID to server, server destroy network object

#

But having client decide over network object despawn sounds like a smell

#

You probably should rethink the whole logic to have the server decide what to destroy

#

In a "somehow perfect" network solution, server is authoritative and client sends only player input

misty gulch
#

👍

patent fog
#

Have fun 👍

severe fable
#

With Netcode NetworkVariables is there a way I can have a nested Array within a struct? For example (screenshot). I cannot use Team struct in the NetworkVariable due to the Jersey[] variable. But Jersey type is INetworkSerializable and can but put into a NetworkVariable by itself.

gusty fjord
severe fable
#

So it would work i changed Jerseys[] jerseys to Jersey jersey1 Jersey jersey2, Jersey jersey3 etc...but that seems bad

gusty fjord
#

I agree that it seems bad. Does your current version throw errors or are you just not getting the correct data?

severe fable
#

It throws this error:

gusty fjord
#

Ah, I see. To be honest I don't know Netcode well enough to give a definitive answer to this. I believe the issue is that the "normal" C# arrays are a managed type, which is why you can't use it in the NetworkVariable. Not super sure if Netcode has a premade solution for this. If not, you could implement your own implementation inheriting from NetworkVariableBase. Would look along the lines of this: https://docs-multiplayer.unity3d.com/netcode/current/basics/networkvariable/index.html#complex-value-types

#

Again though, not sure on this in general and maybe someone knows how to fix your issue without doing this

austere yacht
tulip ledge
#

How do you use delta time? in netcode?

austere yacht
tulip ledge
#

Movement

tulip ledge
#

This happens on both the client and server this move logic

austere yacht
#

you’d only run that code on one side with its local fixed deltaTime and sync the result to the other

#

if you want to make a deterministic sim (where you sync only inputs) you’d have to implement a network tick system and use the tick interval as deltaTime

tulip ledge
#

I call this from onTick

#

minTimeBetweenTicks = (1f / NetworkManager.Singleton.NetworkTickSystem.TickRate);

slow knoll
#

NetCode - Is it good for MMO RPG games ?

austere yacht
broken fiber
#

Hello :D, someone know why in my game i cant get a clientconnection if i'm not a host too, i want to change my player prefab to another variant

#

there is the code:

#

The problem is when i want to get the connectionToClient of my only client this is null :c

mighty whale
#

This is a simple server authoritative movement script I wrote, how can I improve this?

#

By improve, i mean improve security

#

I know i can do !isOwner

wide girder
main token
#

Hi guys, does anyone know how to build the server build when the server build option no longer available? Thanks

vagrant berry
#

Hello! I'm using NGO + Relay and when i'm trying to join a host through a generated joinCode i get that the join code doesn't exist... I have basically copied the docs example for joining and generating with join codes (https://docs.unity.com/relay/relay-and-ngo.html#Configur)

Here's my snippet for joining using TMP input field (see image) I'll also send the error I'm getting

austere yacht
main token
brittle gyro
mighty whale
#

@vestal stump I might be able to help

vestal stump
#

Hey, thanks! Appreciate the very quick helping offer

#

You want me to dm you or just keep everything in this place? 🤔

olive vessel
#

Best keeping it here, then I can be nosy

mighty whale
#

Yes keep it here

vestal stump
#

Alright!

#

So

mighty whale
vestal stump
#

First I had this issue. Things worked with one character, broke the second the second bean got in tho. The host was unable to move, the camera didn't work with him at all, and there were some other annoying issues

#

At this point, each player had his own camera attached to them

mighty whale
#

Let me see the controller code

vestal stump
#

Then I got someone's advice and just used one camera in the scene and referenced it from each individual player

#

It makes the usage of the host character possible, even when I drop the second player into the scene, but now the second player doesn't work.

#

Also, whenever I build my game, for some reason I can't move???

#

It works perfectly fine in the editor game simulation tho???

mighty whale
#

It sounds like you are trying to move the client but the server can’t prove it

vestal stump
mighty whale
#

Just let me see it hypers

#

Please pastebin it

vestal stump
mighty whale
#

Hastebin is best imho

olive vessel
#

New to Unity and C# and doing multiplayer, what could possibly go wrong

mighty whale
#

Netcode is pretty easy

#

At very least, easier than photon

#

Can’t possibly go wrong

vestal stump
olive vessel
#

Citations needed

mighty whale
vestal stump
#

This is my movement script. Also want the camera movement script or is this enough?

mighty whale
#

So what you gotta do is move the actual movement into a ServerRpc

vestal stump
#

....

#

Dumb question

#

What's an RPC

vestal stump
#

"Remote Procedure Call"

#

Hmm

mighty whale
#

I have a simple 2d one moment

vestal stump
#

sure

mighty whale
#

This is like the bare minimum

vestal stump
#

interesting

#

Thanks

mighty whale
#

Obviously you’ll just put your rigid body code in a serverrpc

#

Not the input code

#

The actual part that moves your entity

vestal stump
#

Mhmm mhmm

mighty whale
#

Notably

vestal stump
#

Btw

mighty whale
#

Id recommend not doing multiplayer or Unity without learning c# but we all know you aren’t gunna take the proper steps amiright

vestal stump
#

Does it make a difference whether I use OnNetworkSpawn or Start

mighty whale
#

It depends on the use case

vestal stump
vestal stump
mighty whale
#

Referencing variables no, but doing things that need to be seen by everyone yes

vestal stump
#

Thanks!

mighty whale
#

Network variables yes

#

But not regular variables

vestal stump
#

Mhmm mhmm

#

Still don't exactly know how to work with RPCs but found a tutorial so will look into that

#

Imma go off for half an hour for smth else now, thanks

#

Btw, I doubt just changing the movement will be enough to fully fix this

#

I'm additionally getting the error "GetSceneOriginHandle called when SceneOriginHandle is still zero but the NetworkObject is already spawned!" with my Client

#

No idea what Unity wants me to do

mighty whale
#

Did you create the RPC?

vestal stump
#

not yet, will do in a bit

#

Just thought I'd throw that error message out there before leaving for a while

mighty whale
#

If you have a method called that figure out what’s wrong with it 😂

#

I just know I had this same exact issue you are having now

split loom
#

I'm using Photon to make a multiplayer game. When I call the RPC on the second line in the If statement, it gives me a "Write Failed" exception. It works without the parameter "mouseRay.collider," am I using the parameter call wrong in this method?

#

This is the method I'm calling

#

Oh, it seems that Photon doesn't support this sort of parameter

#

Is there a way to just sync a gameobject component with any changes made?

vestal stump
#

I'm back!

vestal stump
mighty whale
#

What errors is it throwing?

vestal stump
#

The same as before.

mighty whale
#

Is it moving very slightly in the Unity

#

Inspector

vestal stump
#

Everything is perfect with the Host as long as it's the Editor version, but the Client do be doing nothing either way

#

He just

#

Flying, essentially

#

Not even affected by gravity

#

Just staying in the air

#

Also, again, the Build version isn't working while the normal editor version is, even if I just create a single host

#

I can move in the build, but only if I'm not grounded

#

So I can't walk, but jump

#

I can do these things in the editor tho 🤔

terse idol
#

Hi, what's the best networking solution to my games?

wide girder
mighty whale
#

Any particular reason the animations make it to the server for the host but not the client? I did create an OwnerNetworkAnimator recommended by the unity docs

terse idol
#

thoughts on riptide?

wide girder
terse idol
#

probably just a few friends

wide girder
#

As for which one to choose, is mostly a preference thing. Most of them work in a similar way and have similar API. Might want to compare the plans that they offer(including the free plan).

wide girder
#

Might still want to go over and compare the free plans and see of there are any additional limitations

woven kiln
#

Is it possible to remove data from scriptable objects for server build?

#

I have some AnimationClips reference on scriptable objects that i use both on server and client but it is not needed for server

paper blaze
#

Would this be the right channel to ask this? For instance I need my game to access a mySQL database and I want to know the best way to go about it. I was told I should use PHP in the middle instead of accessing my DB directly from my C# code.

austere yacht
#

All frameworks have an equivalent of onNetworkStart and onClientConnected callbacks

spring crane
paper blaze
#

I believe I was directed to use PHP between it.

#

Is that the best/easiest solution?

spring crane
#

It's just a language commonly used for backend stuff, but C# and many other languages get use in the backend too

#

Especially back in the olden days

#

Using a language you know and is capable for the job is probably easiest.

paper blaze
#

OK.

mighty whale
#

I do in fact have the network rigidbody and network animator

mighty whale
#

Ive tried to make it into a network in code and it made no difference

soft helm
#

has anyone here used normcore? my prefab is spawning in a weird spot and im trying to change the default spawn location

meager abyss
#

I'm looking for a cheap/(free if that's a thing) way to host a server for a chess game. Someone told me to use microsoft PlayFab but it does look really scary (like one step to the side and I'm billed hard, I just don't know if it's safe to use).

Do you know any alternatives that don't have that factor ?

soft helm
#

my thought would be probably one of the free plans on aws/azure that then charge a couple cents per overuse

#

or spin up a .net backend you just have running while you play?

#

and use that until launch?

meager abyss
#

alr I'll look into how spending limits are setup in aws then. thank you

little sorrel
#

When I try and use this script the camera is on the other player. I looked in the inspector and player is set to the right player.

using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class MoveCamera : MonoBehaviourPunCallbacks
{
    public PhotonView pv;
    public GameObject player;

    void Update()
    {
        // forEach()
        if(pv.IsMine){
            Camera.main.transform.position = new Vector3(player.transform.position.x, player.transform.position.y, Camera.main.transform.position.z);
        }

    }
}
oblique herald
#

How can i test my steam multiplayer game without having to run into my brothers room every time i want to test something

austere yacht
oblique herald
#

Just says "Client already made"

olive vessel
#

Yeah I don't think you'll be able to test the Steam bit on one PC

oblique herald
#

ye :/ IM setting up a vps rn

forest chasm
#

if anyone is on i need help trying to figure this out, i have my original project open and a clone i all the way up to having the HOST, SERVER, CLIENT. but when i host on my main project and go in the game, and then switch to my clone and join as client i cant see either player on either project, any ideas?

storm canyon
forest chasm
#

i built an ran the game on both projects

storm canyon
#

you play the game in the editor and open the build from that same project. not anything on another project

forest chasm
#

so build it from the original project, host from build the client from unity project?

storm canyon
#

yeah

forest chasm
#

okay will try!

#

didnt work still cant see each one another, i even tried following along unity's golden path and im still having the issue of not seeing client and host

olive vessel
#

Show the setup of the player prefab

#

It might also be useful to add some logs, NetworkManager has a OnClientConnectedCallback

forest chasm
#

i took screen shots i dont know where to find them in file

olive vessel
#

If you use Windows + Shift + S they are copied to your clipboard

forest chasm
#

sorry i still dont know where that is im so sorry

olive vessel
#

If they're in your clipboard, you can just Ctrl + V to paste them here

forest chasm
#

ohhhh

olive vessel
#

And that is set as the prefab on the NetworkManager?

forest chasm
#

i assume so its what spawns when i host or join as client

olive vessel
#

So if you host using the editor, and join as a client using a build, what happens?

#

Can you show the hierarchy of the editor when a client joins

forest chasm
#

ill try that ive only done the other way around

olive vessel
#

Well if you use the editor to host, you can see any errors

forest chasm
#

okay one moment

#

this is the hierarchy on the host

#

not showing the client join

#

but the client is in the "game"

#

no errors

olive vessel
#

What does the client see now?

forest chasm
#

just the scene but not the host

olive vessel
#

Create a script and stick it on the NetworkManager object, give me a minute and I'll write some code for it

forest chasm
#

okay will do thank you so much!

olive vessel
#
using Unity.Netcode;
using UnityEngine;

public class RenameMe : NetworkBehaviour
{
    private void Awake()
    {
        if(isServer)
        {
            NetworkManager.OnClientConnectedCallback += ClientConnectedCallback;
        }
    }
    
    private void OnDestroy()
    {
        NetworkManager.OnClientConnectedCallback -= ClientConnectedCallback;
    }
    
    private void ClientConnectedCallback(ulong clientId)
    {
        Debug.Log($"Client joined with ID: {clientId}");
    }
}

If my Notepad++ code is correct, this should log whenever a client joins the server.
Rename this class to the name of the file.

#

There's a callback for disconnect too, might be handy to add, but this should tell us if the client is actually joining or not

forest chasm
#

okay trying rn

#

two errors

olive vessel
#

Huh, I thought NetworkBehaviour had isServer

forest chasm
#

i fixed the isserver one the i in IsServer was lowercase

olive vessel
#

Oh, Netcode uses proper conventions

#

Unlike the rest of Unity Engine

forest chasm
#

what about the yellow one?

olive vessel
#

It's a warning

#

You can either add override before void on OnDestroy, or just leave it

forest chasm
#

you think ill be fine. the other OnDestory i have is so controlling is indipendent from each client

#

screw it gonna run it

#

okay so no dice

#

i guess the client isnt even joining in the first place

olive vessel
#

So they're on the same machine?

#

And the connection address is 0.0.0.0

forest chasm
#

how do i check that

#

sorry to sound dumb

olive vessel
#

Well that'll be a field on the Transport component, which will be attached to the NetworkManager

forest chasm
#

the address is 127.0.0.1

#

port 7777

olive vessel
#

Yeah that works

forest chasm
#

i guess not for me

austere yacht
#

the server needs a listen address, else nothing can connect (at least it used to be that way)

#

if you want it to listen on all addresses you can set it to 0.0.0.0

forest chasm
#

i set it to 0.0.0.0 still wont work

austere yacht
#

can you be more specific

forest chasm
#

been troubleshooting for the past hour

#

i build and run, host on the project and client on the build both instances join a "game" but i get no debug.log that was made to show when client joins so i know its not joining, also isnt in hierarchy so its just not connecting

#

at first i thought it was connecting i just couldnt see the two prefabs but i now know they arent even connected

austere yacht
#

you should get a log message that the connection failed

forest chasm
#

i get nothing of the such

olive vessel
#

So how do you connect the client

forest chasm
#

well ive run into a new problem, BUT i would try connecting by build running and then hosting from project and then clienting from build if thats what you mean

olive vessel
#

No, I mean how do you do it

#

What says "Go and connect to this server"

#

Where do you tell the client to connect

forest chasm
#

only thing i think i can answer that with is the network manager and unity transport

olive vessel
#

Where have you called NetworkManager.singleton.StartClient()

#

I presume you have also done blah.StartHost() on the server too?

forest chasm
olive vessel
#

Oh for God's sake

forest chasm
#

im pretty sure this is all ive got manually made

olive vessel
#

You use StartHost for all of them

#

Of course it doesn't work

forest chasm
#

wait

#

wait

#

i stg im an idiot

#

well atleast THANK YOU for opening my eyes! im so sorry

olive vessel
#

It's always the simple things

forest chasm
#

but what about the blah.starthost whats that

olive vessel
#

Well that was because I couldn;t be arsed typing out the full thing twice

forest chasm
#

ahhh okay

#

well lets try now

#

but ive run into a new bery recent problem on the build and run clicking host server or client does nothing

olive vessel
#

It probably does do something, but it might not be evident in a build

#

In the editor, you see the change in the hierarchy

forest chasm
#

trying right now