#archived-networking

1 messages · Page 2 of 1

split gyro
#

oh

#

found the package

#

I have no Idea how to use this

gray jewel
#

making a multiplayer 2d game and I can see thru other players camera anyone know how to fix?
(Photon.Pun)

thorn crown
#

There should only ever be one camera per instance.

mighty lake
#

which is better

#

FishNet or the current iteration of MLAPI (Netcode for GOs)?

olive vessel
#

People like asking which is "better" when really you should be asking yourself "Which one do I want to work with?", "Which one fits my project and has the features I need?"

#

Without any details about your project, you can't reasonably expect someone to say one is better than the other

uneven frigate
#

how can i make a system where people watching a game can join, with photon or something else ( my first goal is The server move the model and clients only observe)

brittle gyro
uneven frigate
#

Thank you, I will check that

brittle gyro
# mighty lake FishNet or the current iteration of MLAPI (Netcode for GOs)?

I'm using NCGO personally. It's fairly simple to use if you like to mostly concern yourself with: (send message to all clients), (send message to host), (send message to specific client), (synchronize primitive data between two participants). If you have a host setup rather than a dedicated server, and if your networking solution is very p2p focused, imo NCGO is great. I've learned it pretty much by spending two days reading the docs and watching Tarodev's 2 videos.

mighty lake
#

Yeah, I always wanted LAN multiplayer because most of my games aren't really designed for actual global multiplayer gameplay anyway

#

I'm definitely gonna try Netcode out

mighty lake
#

I am networking my Rigidbody FPS controller, it's working but my players are jittering and are not synced with the actual location of the player

#

This is a huge step to be honest, despite the issue

#

I'll try to fix the issue then build on top of it

#

My decision:

LAN/Party games - Netcode for GameObjects
Full-scale Global Multiplayer (If I ever make one) - FishNet or Photon

mighty lake
#

I get this error ClientRpc method must end with 'ClientRpc' suffix!

#
    public void RpcTakeDamage (int _amount, string _sourceID)
    {
        if (isDead)
            return;

        currentHealth.Value -= _amount;

        Debug.Log(transform.name + " now has " + currentHealth + " health.");

        if (currentHealth.Value <= 0)
        {
            Die(_sourceID);
        }
    }```
#

I am porting Brackey's multiplayer from Unet to Netcode

#

nvm

#

I just have to rename the method

wispy oar
#

does anyone know of any good info or tutorials on how to set up a multiplayer system in a game like escape from tarkov, where players load into a continuous game, play, and get out with the gear they acquired? i've been looking but i cant find any good info on it.

night thunder
#

Can anyone tell me where to find the Unity Netcode for Gameobjects Client Network Transform script ?

#

the documentation links to something outdated, and also is outdated in itself

night thunder
#

@patent fog Thank you so much! <3 Can't for the life of me not understand how this is not directly included in the Network for Gameobjects package

patent fog
#

yeah they hit 1.0 though, could/should have been in main package (?) 🤷‍♂️ Not following closely enough though

weak plinth
#

so fishnet vs fusion does anyone have any performance comparison?

night thunder
weak plinth
#

vs fusion site:

patent fog
#

@night thunder Maybe it will come later, or maybe they consider it a hack and allow it for demo only ? ANd don't really expect you to use it in prod ?

#

Dunno, really blind guessing here

#

🙂

night thunder
#

@patent fog pretty sure that would/should be mentioned on the documentation in some way then... but with all the different versions of editors and packages, i think current Unity is not nearly as beginner friendly as it was at some point 🙂

patent fog
#

True, hard to follow nowadays with all these experimental packages, taking infinity to reach production state 🙂

#

the component kinda warns against itself in the comments

#

and as a general rule, never trust user input, allow the client authority over the Transform seems a really bad idea to me

#

should be 100% okay for a little couch co-op game among 4 friends though

#

like this boss room sample

#

looks like the kind of scope network for gameobject is intended, right ?

night thunder
#

I'm not a coder, I know about clientside/serverside things and how things can be hacked and stuff, I just wanna prototype stuff, nothing for serious production

#

3 years ago i could download Mirror, slap Client Network Transforms on prefabs and bam it was working

#

Nowadays everything becomes such a hassle with unity

patent fog
#

yeah this will be totally fine for learning the ropes, and again, you don't expect you friends to cheat, so as long as you don't release towards unknown public, that'll do 👍

night thunder
#

@patent fog but since we are on the topic and you seem to be quite familiar, most games do infact trust user input first, and only divert from it if the server disagrees with it right? I'm not waiting my 50ms ping for my character to move inside my local game that is networked to a server

patent fog
#

yes you described client prediction

#

but in the first part of your sentence, having the server validate and override the position, is going back to server authoritative model

#

🙂

#

By reading this component class, it looks like it will never let you perform this check on the server side

night thunder
#

How so? The server will always get the position information of the player, and could simply do a check if the new position is even possible to reach given the players movement speed and other conditions, or am I missing something?

patent fog
#

having the server validate client input and eventually fixing it afterwards, is called server reconciliation

patent fog
#

Though I'm talking in the context of this component particularly

night thunder
#

I'm just talking theory here :D I do know C# but I don't know advance mathmatics

patent fog
#

I don't know the internals of Network for Gameobject, but it looks like there's an event when the server will asks to know who's authoritative, the client will grant itself authority. So at this point I guess the server just assume it will not do anything else with this transform```cs
/// <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;
}

#

it's like parents asking their kid if they are allowed to boss them, the kid says "no, thanks" and parents won't even try harder to change the kid's mind :p

#

so now the kids does whatever he wants and parents have no opportunity to intervene

night thunder
#

Is that a set-in-stone thing or can the server still revert this during runtime? Or at least make changes to, lets say position, overriding the local authority?

#

Ah well that answers it

patent fog
#

Again never dig how it works internally, but the name OnIsServerAuthoritative suggests an event callback (because of the OnSomething)

#

I assume that event is checked every frame where a network command is sent (?)

#

or maybe it's a one-time check and then this network object is always trusted ?

#

Don't know really, sorry

#

because it's an event, it makes much more sense that it's not an only once thing

#

So yeah maybe you can change authority during runtime (which is doable for others network libraries actually)

#

And probably removing the component is enough to switch authority (?) 🤷‍♂️

#

Lot of speculation here, I'm talking withtout knowing ^^

night thunder
#

Can a server simply remove components (of a client authority)? I imagine that would be something that could be circumvented locally, but again I'm not really a coder

patent fog
#

The docs surely have chapters about authority, otherwise they don't deserve the 1.0 release tag 😅

night thunder
#

Ah I see :D I Will look into that another time :) Do you know what the purpose of this Client Network Transform is then, if it is advised not to be used (in stuff where server authority is important)? Is it intended for just fun local multiplayer stuff, or just a work in progress and not quite finished yet? Any info? :C Again, the documentation doesn't really say anything in regards to this

patent fog
night thunder
#

Ay okay, so currently people who use netcode for gameobjects are probably writing custom code, I am assuming

#

Was very much hoping for it to be a semi-plug-and-play solution, guess that would be too easy :/

patent fog
#

so yeah to summarize, good for havng things easily sync their movement and quick prototyping, won't cause any concern for fun local multiplayer, never use that for public online commercial project 🙂

patent fog
#

don't have to code your own transport/messaging system, but no it's not 100% plug-and-play, you need to add your own gameplay (though with the samples they made a good job it seems, feel free to inspect their code)
Plus you'd need additional services for hosting and matchmaking for example

amber void
#

if i wanted to set a variable to false after an anim finishes playing, what would be the easiest way to do so?

#

is there a built in unity method that lets u do this?

patent fog
amber void
night thunder
#

@patent fog Thanks for all the insight, very helpful! One last thing I'd be interested in, if you'd be so kind, is how would I imagine someone "hacking" a game, would they just access lets say the variable that controls movement speed somewhere in the ram where its stored, and then since they move fast locally and send position info to the server, the hack would be successful? If so, could I somehow replicate this so I can test my own ideas to catch or prevent this from happening?

patent fog
# night thunder <@317274156578111488> Thanks for all the insight, very helpful! One last thing I...

Dude you sure you're not meant to be a coder ? ;p Yep, you describe a cheat engine. Lets you inspect Memory assignation and find variables.
Also for networked games, you can use sniffers to see webrequests going away from your computer towards the server, and if any param is let for the client to set, you can send your own requests and cheat (let's say for example a buy button for a market: if one of the params is the quantity, you can add way more, hoping there's no server authority ^^)

#

Not sure I can post the link to Cheat Engine, even for educational/debugging purposes only (?)

night thunder
#

Hell no, I get nightmares only by reading the word quaternion, let alone trying to figure out what namespaces are and why I should care >_>
Aight guess its time to experiment then, again thanks for the help!

patent fog
#

haha don't worry quaternions make sense for no human 🙂 Good thing is you don't have to understand them (I don't) to use them. And you didn't pick the easiest of topics as example ^^

#

Alright and time for me to go to bed, glad we could have this little talk

#

Have fun !

mighty lake
#

what's the correct way to network footsteps?

dreamy magnet
#

Please, can someone advise on following

We are currently building a multiplayer game with Unity engine and similar to Mario Kart (https://mariokarttour.com/en-US).

We want to implement a game with Server-Client architecture and want to know a good framework which can work with following requirements:

  • Supports Web-GL, Android and iOS deployments.
  • Independent master and client logic development in separate projects.
  • Server Authoritative with full access to server control and deployment .
  • Integration of 3rd party services such as Matchmaking, Leaderboard, Analytics, Remote Game Config, etc.
  • Dedicated support/ Community Support

Thanks!

orchid mango
#

I couldn't find a better place to ask this, so here goes... Where are Unity's logs located from running a headless server on an Linux machine (Ubuntu)? Thanks in advance.

summer anchor
#

having a few issues using mirror networking, my players cant see the animations, even though i have a network animator on client auth with my animation linked, and the players also seem to flash and fall through the ground then back up repeatedly, any ideas what could cause this?

austere yacht
haughty geyser
#

im trying to get JSON data from an API call, but im getting HTML data instead, does anyone know why?

#

i want to call this :

#

i did this :

#

when i open the link manually, it shows the JSON data

#

is it possibly because of cloudflare or something doing browser checks?

haughty geyser
austere yacht
#

just look at the html what it says

haughty geyser
#

it says "checking browser:"

austere yacht
#

thats cloudflare

#

it makes sure there are no automated queries

haughty geyser
#

hmm

austere yacht
#

usually your target service would have an API that takes some form of authentication (a token) that binds the request to a user account for rate limiting

haughty geyser
#

ah okay

#

thanks a lot for the info

final vault
#

Hi, what is the proper architecture and library for making and deploying WebGL multiplayer game
I'm learning PUN now and they said PUN doesnt really support WebGL socket well, they recommended using their server Photon Cloud
I also read somewhere and they said I should make a server using node.js, but i dont really know sure how to combine that with PUN and how to override PUN socket
anyone have experience in this?

stiff ridge
#

I have no idea where you get your info but that's mostly wrong, sorry.
PUN supports WebGL but we'd recommend Fusion by now. It's a much more up to date networking solution and also supports WebGL.
The Photon Cloud is the managed backend for PUN and Fusion alike. It makes your life easier as it provides matchmaking, load balancing and more without the need to setup and run machines yourself.

final vault
#

thanks for your response. I will try to learn it.

dreamy magnet
#

@austere yacht Thanks for response are there any suggestions.

Cons: If server and client logics are on same project, I think there will be security issues.

summer anchor
#

Having issues with mirror, my players seem to flash there and not and also fall into the ground and back up, and my weapon animation doesnt show either, ill attach my player controller code and a screenshot if anyone can help me out it would be appreciated, been stuck on it for a while now and dont want to continue until i can sort it out, cheers

The animation code is on the last line in firing, not sure if i have done that wrong and thats why animations dont show? im very new to unity but mainly just want the player flickering / falling fixed. I also have a network animator on the player and linked the animator on the pistol

https://gdl.space/ojojirozos.cs

orchid mango
#

I looked through those but the closest I could find does not point to the files, that's why I had to ask here. @austere yacht

austere yacht
light blade
#

Hi, I'm currently exploring the unity's netcode for gameobjects for my online board game. I just started to implement the multiplayer aspect (starting from generating the board) but I get the issue where the client cannot spawn some cells locally but the server did spawned everything correctly. I worked along the API documentations and tutorial. These are the console logs. I'm sure the prefab for the spawned cells is registered in the NetworkManager. The missing pattern though is the same every time but also doesn't have a specific pattern so I cant quite figure out what went wrong with the generating algorithm either. I am very new so may be the log would help me identify the problem I've done that I don't know . Could someone help me , sorry I'm a beginner.

summer anchor
flint cove
#

A guy is helping me make a game in Unity and I had a question regarding storing the player's info and stats, as to help prevent hacking and modifying the file. We are using Photon for the game server, but as far as the player's information and having accounts linked to them, what would anyone recommend? Thanks!!

candid path
#

im new to doing multiplayer things and am trying out unity netcode, how can I send a message to the host for example "jump" from a client

austere yacht
flint cove
#

Or who would...?

austere yacht
lofty grail
# mighty lake what's the correct way to network footsteps?

IMO the way to do that would be to not network it at all. That is, footsteps should be left behind by the local instances, so they would require no network sync of their own. Assuming whoever is leaving footsteps behind is already net synced, that way wherever those are in any given client, they would be leaving footsteps behind themselves.

#

that is to say, I'm assuming it's preferable to have footsteps be visibly consistent with whatever is leaving them behind than to be accurate to the actual path travelled, so there is no need to ensure each footstep is synced. It can just be a local effect that happens on each client.

pseudo sapphire
#

Hey guys. Just started working on a prototype for a multiplayer game using Netcode for Gameobjects.
With 2 players spawned in I cant move the client player at all unless I disable the Network Transform component but then it doesnt update the position. Am I missing something?

#

Also if this helps. This is the movement script

jaunty yew
#

Hi, I wanted to make a multiplayer game and upload it to unity but it says that photon doesn't support webGL builds. Is there another multiplayer runner that supports webGL?

#

Or can you make multiplayer WebGL games with photon? It's actually not that clear

high rose
#

I understand that the basic package does not support it tho

#

Unity Multiplayer with webGL is definatly possible somehow, theres many internet games made with unity that have managed it somehow

#

such as Fall boys lmao

high rose
mighty lake
#

Also, don't use NetworkTransform

#

use ClientNetworkTransform

#

it overrides the former by making it not require ownership to interact with Rigidbodies

#

Also noticed you are working on 2D, my bad

mighty lake
pseudo sapphire
#

I dont seem to have a ClientNetworkTransform.

mighty lake
#

Hold on

#

Here you go

pseudo sapphire
#

Ahh so we need to write everything ourselves in that script?

mighty lake
#

Nope

#

It is essentially NetworkTransform

#

Just attach that script to your player and see what happens

pseudo sapphire
#

How do we import it? Using the url doesnt add it in Unity

mighty lake
#

Just copy paste the code

pseudo sapphire
#

Am I missing something? Its 22 lines and seems to be only overrides. Nothing is actually doing anything

mighty lake
#

You're not missing anything

#

That script is the only thing you will replace NetworkTransform

#

You don't need to download the whole github repo

high rose
#

For some reason, this script isn't syncing My default Player prefabs transform across the different clients

#

Would appreciate any help on this thanks!

covert gull
#

How does fishnet compare to unity's netcode for game objects? I saw some performance benchmarks where fishnet looks faster. Wondering what feature differences there are though? Anyone have any experience with either?

high rose
covert gull
#

Awesome thank you!

high rose
#

whoops lol

#

alg

covert gull
#

@high rose can you dm me? lol

#

the link

high rose
#

its in the pins

covert gull
#

ah, thanks!

neat veldt
#

Networking newbie here, should I put the lobby system in a separate scene from the game or is that overcomplicating it? I'm using netcode for gameobjects and the lobby/relay system if that matters

pastel mauve
#

I normally do, just to keep things seperated

#

I need much help

#

I normally don't ask for help but I've been struggling with this for a good few days and I have no more clue as to what is happening

#

This is my script, and it's worked fine for a few months, but as soon as I made my project build for IL2CPP and UWP, it stopped working

#

most of it is ignorable and game-specific, but the important part is that ConnectUsingSettings() returns true, but the state is "Connected to NameServer", and OnConnectedToMaster() never gets called

#

After changing the photon dlls to use IL2CPP and enabling full logging, I get this cool error(about 1 every 3 frames) that google seems to know nothing about:SendOutgoingCommands ignored socket is not connected. pid:65535 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object) UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[]) UnityEngine.Logger:Log(LogType, Object) UnityEngine.Debug:Log(Object) Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String) ExitGames.Client.Photon.EnetPeer:SendOutgoingCommands() ExitGames.Client.Photon.PhotonPeer:SendOutgoingCommands() Photon.Pun.PhotonHandler:LateUpdate()

#

any help is helpful, and if you decide to reply (with any ideas), ping me

spring crane
inland pier
#

what function can i call in photon that will run when a player joins the room

pastel mauve
#

I was just grabbing at straws (is that the expression?) but I can change it back

south palm
#

any recommendations for what to use for networking? are photon and mirror different modules?

hard dagger
#

so, I was trying to understand what kind of servers does multi player games like fall guys or Valorant use?
Does the services deployed there use UDP for relaying information about other players and their state , and then gRPC for invoking actions?

or is it simply gRPC or webRTC for everything?

neat veldt
#

I'm trying to set up relay but I get this error when trying to create an allocation:
nvm i just messed up the argument order

neat veldt
#

I decided to go with netcode that just released and so far I'm impressed by how easy it is to setup.

pastel mauve
hard dagger
#

Ok but there must be some code/running on it, right?

So what protocol is used for multiplayer stuff.... or specifically if i want to create one such server what would i need to do?

pastel mauve
#

you could try writing your own server with nodejs and host it with say heroku

#

it most likely wouldn't be as fast as PUN or NetCode because those are insanely optimized, but if you're willing to try go ahead

hard dagger
#

i dont suppose the server would be RESTful

#

So what kind of api would i need to create

pastel mauve
#

most likely websockets

#

I've only used nodejs for web-based games and websockets are the best mo

#

imo

#

I'm not sure how to integrate that with unity, but there are def tutorials

hard dagger
#

Cool

#

Thanks man!

azure mango
#

Hi! I'm taking a look to the new networking for gameobjects, but I can't find how to use it with the steam transport. Anyone has a solution?

patent fog
#

(Never tried it, I just know it's there)

#

I'll let you try 😛

azure mango
#

Yeah haha, I just found that too!

#

But it seems like there are two Steam options, SteamNetworking and Facepunch

#

I will need to check the differences

patent fog
azure mango
#

Thanks! ❤️

patent fog
#

You're welcome, have fun

azure mango
#

So, I installed the package.. but I can't find the facepunch transport..

patent fog
#

Looks like you installed the ENET transport, and it is indeed in the list

#

By quickly reading the wiki, looks like facepunch get installed by dropping the dll files into your project, not through the package manager

#

Actually wait

#

the community extensions though, do get their install through the package manager

#

might be easier 🙂

#

Oh I see now, you blindly followed these instructions

#

you need to switch enet with whatver transport you'er interested in

#

@azure mango Hope that makes sense and get you unstuck

#

Sorry couldn't warn you before because I didn't try netcode for gameobject yet, just discovered that right now while investigating for you ;P

azure mango
#

Oh lol I understood that wrongly xd, I readed like, with this you install everything and then select the transport 🤦‍♀️

#

Thank you hahaha

patent fog
#

Actually now that I'm reading it, you might be interested to install the whole extensions package, not only the transport

#

Comes with some nice additional utilities

#

but depends on your game, as you see fit 😉

azure mango
#

Oh I'm just in the testing stuff moment haha

#

But yeah it could be usefull

patent fog
#

Have fun !

azure mango
#

n.n

hard dagger
austere yacht
#

Websocket is always TCP

summer anchor
#

Whats the best way to do weapon movement? i have a parent constraint linked to my main camera and it works well for the player, but it doesnt sync over the network as moving up and down

austere yacht
summer anchor
austere yacht
#

then sync the transform of the weapon

summer anchor
#

It rotates with the player body but just unsure on the up and down movement that follows the canera

#

I thought it'd be fine with a parent constraint as the weapon is apart of my player (only have 1 wep so far)

#

As the player the gun rotates to follow the camera just others don't see that

austere yacht
#

you still need to sync it

summer anchor
#

Rogey I'll look into hpw to sync a transform

#

Very new to unity, first project 😂

austere yacht
#

it’s a component

austere yacht
summer anchor
#

Yeah I know, I like the challenge though, more doing it for fun. Just making a basic co op shooter to mess aroubd with mates

austere yacht
#

it’s not the challenge

summer anchor
#

Never going to be a finished game haha

austere yacht
#

it’s just impossible to do it sensibly without knowing the engine before setting it all up

summer anchor
#

Got my map made, players , water, wind, reloading, ammo count, health and basic ui, just gotta work on shooting and respawn and I'm happy haha

austere yacht
#

and multiplayer being multiplayer, you can’t just change it all mid project

summer anchor
#

Yeah I know I'm probably doing stuff in a bad way, watching videos and mashing what I learn together

austere yacht
#

But good enough for having fun with it for a while

summer anchor
#

ive learnt xD

#

as i said, more a hobby than anything

#

quick one, would it be a network transform or transform child as its a child object?

austere yacht
#

child

summer anchor
#

rogey

half anchor
#

Hi. I’ve read multiple times that a multiplayer objects makes the game 3x the effort so I’ve always avoided it. However, seeing that network for gameobjectss is 1.0 I keep thinking it might not be like that

#

The use case for my game is co-op, so it allows me to ignore the anti cheat, match making and public server aspects

#

Does this still mean 3x the effort?

austere yacht
#

you can still do the exact same things with the exact same amount of effort reaching the exact same performance you could before with other packages

#

the idea that netcode for gameobjects is only for coop peer to peer multiplayer (code monkey opinion) is silly btw.

half anchor
#

Oh I wants trying to say that (I didn’t see that opinion from code monkey)

#

I was more asking if coop peer to peer is something that is feasible or if it 3x the project size as people usually mention

spring crane
spring crane
austere yacht
spring crane
# austere yacht Maybe that’s because it doesn’t have any builtin mechanisms that facilitate comp...

It probably is primarily that, but I have no idea what kind of reworking of the MLAPI they have been doing and what the state of that might be.
I think the "you can still do the exact same things with the exact same amount of effort reaching the exact same performance you could before with other packages" is misleading unless you start every project on these frameworks by completely removing everything except the low level messaging API.

#

Even then you are probably going to find pretty major differences

austere yacht
summer anchor
#

What is the best way to move my weapon up and down? having trouble getting it to sync. It works fine for the player but for the other players they see the weapon staying still. It rotates with the player body but i cant seem to get the up and down to sync to other players. I have tried putting it under the main camera, but then players cant see the weapon at all, maybe because main camera is disabled if youre not the main player? i have also tried having it under the player body and using a parent constraint, works good for the player but still stays still to the other players.. Have also tried a network transform child that didnt work either. What is the best way to sync the up and down movement?

tawny glen
#

Help I am going crazy I am using NetCode and a really basic character, when I start as a host it works and as soon as my client joins I can not control host character anymore cuz both controll the client that joins

onyx flame
tawny glen
#

@onyx flame I have that in my update loop

onyx flame
#

I don't really know then sorry.

tawny glen
#

Thank u for trying atleast :)

#

Anyone got any ideas? it all works fine but when a client joins the host can not move his own character anymore only the client

tawny glen
#

Let me explain more detailed: When I host the game it works fine I can move the character normally and when I join on a client the client can move exactly like it should but when I go back to the host the camera has frozen and the host controlls the client and the client controlls the client so the host is left unmoveable.

#

This is the character

#

I really hope someone can help me I am new and I really want to learn :(

willow arch
#

Please can someone please help me out, only the host can move and I can't figure out why my code isn't working. I am very new to unity networking

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

public class PlayerScript : NetworkBehaviour
{
    public Rigidbody2D rb2D;

    public NetworkVariable<Vector2> Position = new NetworkVariable<Vector2>();

    public float speed = 10f;

    void Update()
    {
        if (!IsOwner) return;

        Move();
    }

    void FixedUpdate() 
    {
        if (!IsOwner) return;
        
        rb2D.MovePosition(Position.Value);
    }

    public void Move() 
    {
        if (NetworkManager.Singleton.IsHost)
        {
            Position.Value = rb2D.position + GetInput();
        }
        else if (NetworkManager.Singleton.IsClient && !NetworkManager.Singleton.IsHost)
        {
            MoveServerRpc();
        }
    }

    [ServerRpc]
    void MoveServerRpc()
    {
        Position.Value = rb2D.position + GetInput();
    }

    private Vector2 GetInput()
    {
        float x = Input.GetAxis("Horizontal");
        float y = Input.GetAxis("Vertical");

        return new Vector2(x, y) * speed * Time.fixedDeltaTime;
    }
}
onyx flame
#

If movetoward() is inside fixedupdate is it deterministic?

tulip ledge
#

Question I'm trying out the new Unity netcode but if I spawn a player prefab the client is not the owner of the object?
Which seemed strange to me? is this correct?

onyx flame
#

The client would be the owner of the player prefab

#

If there are 4 clients there will be 4 prefabs and each client will be the owner of one of those prefabs

tulip ledge
#

Ah I tried it like this now

        public override void OnNetworkSpawn()
        {
            if (IsOwner)
            {
                examplePlayer = Instantiate(playerInputPrefab);
                exampleCharacterCamera = Instantiate(cameraPrefab);
            }

            if (IsServer)
            {
                exampleCharacterController = Instantiate(playerPrefab);
                exampleCharacterController.GetComponent<NetworkObject>().Spawn();
            }
            
            if (IsOwner)
            {
                examplePlayer.Init(exampleCharacterController, exampleCharacterCamera);
            }
        }```
#

But didn't seem to work

onyx flame
#

In your network manager in the scene is there a player prefab assigned?

tulip ledge
#

Ah I see, the example CharacterController is null as it is being spawned on the server so it loses refference

#

I guess there is not an easy way to find that instance or you spawned player

patent fog
# tawny glen

I think you're not supposed to use Start and awake methods with network. It might mess with your host's rigidbody reference when your client joins, I assume.
Better use the joined callback (don't remember how they're called)

patent fog
patent fog
onyx flame
tawny glen
summer anchor
#

so i have a raycast with a trail on for when i shoot my gun, how can i sync the trail across the network so other people can see it?

austere yacht
#

you drive it with the same parameters on all clients

tawny glen
#

movement seem to work fine now but as soon as a new player joins everyones camera goes to them can someone see what i am doing wrong

using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

public class FirstPersonLook : NetworkBehaviour
{
    [SerializeField]
    Transform character;
    public float sensitivity = 2;
    public float smoothing = 1.5f;

    Vector2 velocity;
    Vector2 frameVelocity;

    private void Awake()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    void Update()
    {
        if (!IsOwner) return;
        // Get smooth velocity.
        Vector2 mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
        Vector2 rawFrameVelocity = Vector2.Scale(mouseDelta, Vector2.one * sensitivity);
        frameVelocity = Vector2.Lerp(frameVelocity, rawFrameVelocity, 1 / smoothing);
        velocity += frameVelocity;
        velocity.y = Mathf.Clamp(velocity.y, -90, 90);

        // Rotate camera up-down and controller left-right from velocity.
        transform.localRotation = Quaternion.AngleAxis(-velocity.y, Vector3.right);
        GetComponentInParent<FirstPersonMovement>().transform.localRotation = Quaternion.AngleAxis(velocity.x, Vector3.up);
    }
}
austere yacht
tawny glen
#

@austere yacht sorry I am now how do I fix that?

austere yacht
#

check NetworkBehaviour.IsLocalPlayer

If a NetworkObject is assigned, it will return whether or not this NetworkObject is the local player object. If no NetworkObject is assigned it will always return false.

tawny glen
#

I have a networkobject assigned to the player prefab do I need one for the camera aswell?

austere yacht
#

the camera does not need to be synced

#

it just needs to follow/point at the right object and be controlled by the right inputs

tawny glen
#

okay

tawny glen
#

im really sorry im so stupid i appriciate u helping me

austere yacht
#

well, i would advise you understand the concepts so you can decide for yourself if its "good"

#

if you ask if the code you show is good, then no, its bad code

#

but it may work or produce the effect you want regardless of that

tawny glen
#

it does not work the client can not move its camera

#

and the hosts camera gets set to the clients camera on client join

austere yacht
#

well, host based netcode is confusing

#

you just have wrestle with it until you figure out why it isnt working

#

and you can only figure that out by really understanding what it means to do do host based vs dedicated server

tawny glen
#

i have been trying for days lol

austere yacht
#

how did you approach solving it?

tawny glen
#

tbh im so lost rn lol

austere yacht
#

well, you picked the most annoying and difficult way to learn multiplayer

tawny glen
#

what is the easier

austere yacht
#

its much easier if you do it with a dedicated server

tawny glen
#

oh

austere yacht
#

then you can ignore all the cases where the client is also the server and all your assumptions about authority and ownership get messed up

tawny glen
#

hmm okay

#

thanks for the tip

austere yacht
#

maybe there is a way to do simple multiplayer without authority in a host-based architecture that is easy to understand but idk about that, authoritative host based multiplayer is a mess to understand

austere yacht
# tawny glen thanks for the tip

conceptually what you need to do is: direct all input only to the local player and on join attach the camera to the local player (not the new join)

public class Player : NetworkBehaviour {
  void OnNetworkStart() {
    if (IsLocalPlayer) {
      GrabCamera();
    }
  }

  void Update() {  
    if (IsLocalPlayer) {
        ReadInput();
        HandleInput();
    }

    if (IsServer)
       TickSimulation();
    if (IsClient)
       HandleUpdatesReceivedFromServer();
  }
}
tawny glen
#

im trying to make a co op game that wont really matter if there is "cheating" lol so how do i just let the client manage everything

austere yacht
#

there is always a server that handles distribution of the updates and you need to send all updates to it so it can do that, you just don't have to worry about permissions and validation, meaning you can force the server to do what a client tells it instead of having clients ask nicely for it to do something, in both cases you have to deal with conflicting requests from different clients, that's what ownership does and to keep thinks simple only the owner of a thing can change it. the only thing authoritative servers do is retain that ownership on all objects but the player objects which then are generally only used as communication routers.

#

in a way clients handling stuff themselves (each running their own sim) is more complicated than doing it all on the server (running one shared sim)

tawny glen
austere yacht
#

have you followed one of the example projects?

tawny glen
#

okay i got somewhere both cameras work as the should but the client can not move only look around

#

idk why tho

#

should I use a client network transform or network transform on my player prefab

tawny glen
#

guess i will just have to give up on my dream

willow arch
#

I have an issue where my client player moves a lot slower than the host player does anyone know how fix it?

onyx flame
#

How can I send messages to all clients as a client?

opal mango
#

How can I spawn a object as Client? I'm to stupid! I only can find answers on how to spawn as Server but I just want to spawn a GameObject with ownership as Client

#

Just how

onyx flame
#

GetComponent<NetworkObject>().SpawnWithOwnership(clientId);

onyx flame
opal mango
#

I just want to spawn with an ServerRpc or whatever idk

onyx flame
#

Yeah you could call a server rpc and give ownership to the one that called it

onyx flame
opal mango
# onyx flame Yeah you could call a server rpc and give ownership to the one that called it

Ye but I have this Problem:
I instantiate a Object on a Client, I want to spawn the NetworkObject-Component, buuuut all th einformations about the Object are on the client. The server has no Idea wich Object this is and I dont know hot to say to the server as a Client something like:
Ayo mister Server, see that NetworkObject overthere? Spawn it! And the Owner shall be ClientID...

onyx flame
#

https://www.youtube.com/watch?v=3yuBOB3VrCk&t=2s at 43:15 he talks about spawning network objects

🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
👇 Click on Show More
🎮 Get my Steam Games https://unitycodemonkey.com/gamebundle

Quantum Console https://assetstore.unity.com/packages/tools/utilities/quantum-console-211046?aid=1101l96nj&pubref=ngo
FREE Third Person...

▶ Play video
onyx flame
#

He doesn't really talk about giving ownership though

opal mango
onyx flame
#

GetComponent<NetworkObject>().SpawnWithOwnership(OwnerClientId);

#

this should work

opal mango
onyx flame
#

can you check if(IsOwner)
GetComponent<NetworkObject>().SpawnWithOwnership(OwnerClientId);

opal mango
onyx flame
#

When you call the serverrpc to spawn the network object from your client also send OwnerClientID and on the server say GetComponent<NetworkObject>().SpawnWithOwnership(sentOwnerClientID);

#

I guess try that once?

opal mango
onyx flame
onyx flame
onyx flame
#

globally unique id

opal mango
onyx flame
#

if you have a list of prefabs you'd like to instantiate and send an index of the prefab you want to instantiate instead of the whole thing you could grab the prefab from the list given the index on any device

opal mango
onyx flame
opal mango
#

*on the client

onyx flame
#

someone else may be better suited to help you. I'm working on a project that is deterministic so all of my objects are instantiated locally and I only send input.

#

but yeah i'd instantiate them on the server and not worry about ownership

violet kelp
#

if/when i make my game multiplayer, how would i go across making your player see something that others cant? for example, the fps hands have to be put in a janky looking position to look right in the camera, but i dont want other players to see it since it looks really weird from any other perspective. how could i basically create a set of hands that only the player sees, and a set that only other people see

#

ping me if your responding please.

weak plinth
#

Or play with Layers

delicate parrot
#

Howdy smart people! Can someone provide a solid guide on using and understanding how to get started with Mirror? Their on site tutorials show you how to get it running with steps and code snippets but I can’t find anything that explains what each new line and piece of code actually does and how to utilise them outside of that specific tutorial

modern oracle
#

Hello, can someone guide me?

I'm trying to make a game. In which user have to connect with its Facebook. Not sure how games show the Facebook option to login through Facebook.

If anyone can guide me, that would be great.

severe fable
#

When using Netcode with unity lobby/relay service is there any way to get lobby pings? So for example I'm doing Lobbies.Instance.QueryLobbiesAsync() to pull a list of lobbies. Each lobby has a Relay join code. Is there a way i can get the ping to each lobby host?

civic flicker
#

hello, i cant seem to be able to install the Multiplayer Samples Utilities to have ClientNetworkTransform component

sullen crag
civic flicker
#

i cant seem to download mine

patent fog
#

or install a package from git URL "https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop.git?path=/Packages/com.unity.multiplayer.samples.coop"

civic flicker
#

thanks!

#

for some reason im not able to find that package through the git URL

patent fog
#

Uhm should work

#

Without the double quotes

civic flicker
#

maybe mine is outdated since last time i used unity was some months ago

tacit stratus
#

Hey guys I have been working on a game using Netcode for Gameobjects and everything seemed to be working fine until I attempted to only have two build versions connect to eachother. When it’s the editor + a build connected together it all works properly and everything is correctly set. However whenever I have two builds playing together a lot of my ServerRPC seem not to work and it seems that a lot of data is not being sent over.

indigo talon
#

Hell everyone!

#

I am currently following a tutorial on netcode

#

and it is made my code monkey

#

at the start everything seemed to work

#

at the time I reached the animation part the animation worked fine but the client couldn't move only the host and second of all my client network transform was also added

weak plinth
#

What is the best way to get multiplayer into my game?

#

Like Photon?

olive vessel
#

Photon the company has many products like Fusion and PUN

weak plinth
#

and what is the best?

indigo talon
weak plinth
#

Cause I have trouble to sync the states (true and false, and vars) on PUN

indigo talon
#

Have you searched that on google?

weak plinth
#

yeah

#

I alr found smth but it is so complicated and Time wasting. There has to be an easier way

indigo talon
#

I will try to simplify it

weak plinth
#

for what?

indigo talon
weak plinth
#

thats easy in the video but not in reality xD

indigo talon
#

I will check the video out and simplify once I have time

olive vessel
#

There's loads of networking solutions, if you don't like PUN try out Netcode for GameObjects or Mirror

#

Remember that multiplayer games can get really complicated really fast

sullen crag
#

Hello, do someone know how can I setup netcode so I can play from different internet connections??

tulip ledge
#

Hello,

I'm trying to spawn a character on the server through a class, I want the client to have a reference to this spawned object.
How would I do this easily?

#
        {
            characterController = Instantiate(characterControllerPrefab, transform);
            characterController.GetComponent<NetworkObject>().SpawnAsPlayerObject(OwnerClientId);
            
            if (IsOwner)
            {
                playerCamera = Instantiate(playerCameraPrefab, transform);
                playerInput = Instantiate(playerInputPrefab, transform);
            }
            
            characterController //how can the client know here about this class
        }```
civic flicker
#

how do i create multiple cameras?

#

so each one follows each player

austere yacht
civic flicker
civic flicker
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using Unity.Netcode;

public class NetworkCamera : NetworkBehaviour
{
    [SerializeField] private CinemachineVirtualCamera virtualCamera;

    void Update()
    {
        var playerTag = GameObject.FindGameObjectWithTag("Player");

        virtualCamera.LookAt = playerTag.transform;
        virtualCamera.Follow = playerTag.transform;
    }
}
austere yacht
#

and you should have the local player inject itself into the camera or a manager script, much more straight forward that way

#

you could maybe also find the local player via NetworkManager.LocalClient.PlayerObject

civic flicker
#

im sorry im completely new to netcode and networking

austere yacht
#

not into the camera, into your networkcamera script

#

and you do that like with any other script

civic flicker
#

if (IsLocalPlayer)
{
have camera follow player(?)
}

civic flicker
#

i'd put the script in the player instead of the camera

austere yacht
civic flicker
#

that makes more sense yea

civic flicker
civic flicker
austere yacht
#

maybe you need to work a bit more on the overall unity and C# fundamentals

civic flicker
#

and im just confused asf too

#

and yea been a while since i last used unity gotta recheck it again

austere yacht
#

well, netcode is confusing at the best of times, if you are also confused about c# and unity stuff you'll have a tough time

civic flicker
#

nono

#

i just mean

#

so i was using tags right

#

im just asking how i'd use the IsLocalPlayer

#

i know it inherits from NetworkBehaviour

austere yacht
civic flicker
#

ah alright i was just confused about that

#

since the docs didnt really seem to answer my question, or i didnt search well enough

#

ill give it a shot

#

thanks!

civic flicker
#

but i added a camera for each instatiated player

#
[SerializeField] private CinemachineVirtualCamera virtualCamera;

    void Start()
    {
        virtualCamera = GetComponent<CinemachineVirtualCamera>();
    }

    void Update()
    {
        if (!IsLocalPlayer)
        {
            virtualCamera.enabled = false;
        } else
        {
            virtualCamera.LookAt = this.transform.parent;
            virtualCamera.Follow = this.transform.parent;
        }
    }
#

basically the camera will always look at its parent object which is the player

#

thank you for the help

#

this might not be the best solution but im satisfied for now

karmic dagger
#

Could anyone help with with this problem

#

So when u create a room the player is fine but once the 2 player join both players cant move does anyone know why this is???

high rose
#

Hi there! I'm getting an error, Invalid network endpoint: 192.168.1.137:7777. Where 192.168.1.137 is the IPv4 of another computer on my network running a build of my project. Why might this be? (Please @ me if you respond) Thanks!

#

It may be important to note that on one computer, I'm inside the unity editor, and on the other one I'm running a build. I have also not muddled with server listen address at all.

austere yacht
high rose
#

it was an example on the docs

#

but doesnt seem tto be working

austere yacht
#

well, you need to be more exact

#

the port should go into the port field and the address into the address field

#

this format of ip:port probably isn't valid

low spoke
karmic dagger
#

How do i use photonNetwork.instantiate scene object???

wide solstice
#

Hello. I am working on a Multiplayer Game with NetCode for gameobjects and was wondering how to have a script run on the server and not clients. I would like the server to have a countdown to spawn in objects. I’ve tried serverRpcs but then it runs multiple times depending on how many clients there are. Any help will be very much appreciated

austere yacht
wide solstice
#

How would I ensure it only runs once?

karmic dagger
wide girder
shrewd violet
#

Helo, small question sorry if its stupid. I have a ClientNewtworkTransform (netcode for gameobjects 1.0), how can I code something like a ClientNetwrokMeshRenderer? That means, making changes from a client to its mesh renderer, and it being reflected on every other client and the server?

#

Should I use a server rpc, or a network variable, or is there something else available to achieve this?

wide girder
shrewd violet
#

In this case, change the whole material

#

From one predefined material, to another (in a list)

#

This code will not work, as the client never updates the server not the rest of the clients

wide girder
#

If it's something like a skin, I'd just share the skin Id or something. Then apply the correct material locally.

shrewd violet
#

ok, so a server rpc then? which takes and applies that effect to all the players?

#

in this case, the material with its id

wide girder
#

Yeah, an RPC would work.

shrewd violet
#

ok, thanks

karmic dagger
#

I was looking through

#

And couldn’t really see anything

#

To do with it

karmic dagger
#

Yeah

#

So i found out eventually

#

About the syntax

#

But

#

It doesn’t really work how i want it

wide girder
#

How do you want it to work?

karmic dagger
#

So i have the player in the scene not as a prefab

#

And i want it so that when 2 players connect it uses the player from the scene

#

Not the prefab

#

And then gives every player a random number between 1-2 depending on what team they are

wide girder
#

I don't think that's possible. You'll have to instantiate them manually via an rpc.

wide girder
#

It's not using the rpc, but network events instead

karmic dagger
#

Yeah but on the manual instantiation it still uses a prefab

#

Im kinda confused

wide girder
#

It doesn't have to be a prefab. It uses the default unity Instantiation, so it could be any object.

karmic dagger
#

Can it be a object from the scene???

wide girder
#

Yes. Any unity object as I said.

#

Should probably look at unity instantiation if you ask questions like that. 😄

karmic dagger
#

Would i have to do instantiateSceneObject???

wide girder
#

no

karmic dagger
#

Something

#

Never for the player

wide girder
karmic dagger
#

So would i have to write this public void SpawnPlayer()
{
GameObject player = Instantiate(PlayerPrefab);
PhotonView photonView = player.GetComponent<PhotonView>();

if (PhotonNetwork.AllocateViewID(photonView))
{
    object[] data = new object[]
    {
        player.transform.position, player.transform.rotation, photonView.ViewID
    };

    RaiseEventOptions raiseEventOptions = new RaiseEventOptions
    {
        Receivers = ReceiverGroup.Others,
        CachingOption = EventCaching.AddToRoomCache
    };

    SendOptions sendOptions = new SendOptions
    {
        Reliability = true
    };

    PhotonNetwork.RaiseEvent(CustomManualInstantiationEventCode, data, raiseEventOptions, sendOptions);
}
else
{
    Debug.LogError("Failed to allocate a ViewId.");

    Destroy(player);
}

}???

wide girder
#

A player is a gameObject like any other, so there's no much difference.

karmic dagger
wide girder
karmic dagger
#

Ye the one from the scene

wide girder
#

Then it should be fine I guess. You just need the to add other part that receives the event as well.

karmic dagger
#

Would it be in the same script??

wide girder
#

I've no clue where you put the first part, but it shouldn't mater that much as long as the script is in the scene.

#

aah

#

actually

karmic dagger
wide girder
#

Yeah, it should be fine.

karmic dagger
#

Called spawnplayers

#

So should i put the other part into the spawn players script to

#

Or make a different one??

wide girder
#

It can be anywhere, since it's a photon event. Logically it makes sense to put it in the spawn script.

karmic dagger
#

Yeah makes sense

#

Let me try and see if this work thank u so much for the help

#

Why am I getting all these errors???

wide girder
#

Probably missing a namespace using

karmic dagger
#

I have photon.pun

wide girder
#

what does you IDE sugest?

karmic dagger
#

Using photon.realtime

wide girder
#

Then do it

karmic dagger
#

Yeah i added the 2 i needed

#

But i still have errors

#

It says for me to make a public byte

wide girder
#

Share the whole script and the error details

karmic dagger
#

And here is what’s causing an error

wide girder
#

what does your IDE suggest?

karmic dagger
#

Making a public byte

wide girder
#

Make it then.

karmic dagger
#

But it also suggests other things

#

Ok made the byte

wide girder
karmic dagger
#

Oh so making the byte was the problem???

#

Not making

#

It didn’t work the 1 players loading in and when the 2 player loading in the 2 player cant move and the 1 player can’t see the second player and the 2 player can’t see the 1st

wide girder
#

Then you're doing something wrong. Share the updated code

karmic dagger
wide girder
#

Does photon print any logs in the console?

#

Are there any errors?

#

If photon doesn't print, increase it's verbosity

#

Could be that event code is not available. If you don't assign it value, it's gonna stay 0. And 0 is probably occupied by Photon internal events already.

#

Either way, seeing the logs should shed more light on the issue.

karmic dagger
karmic dagger
wide girder
#

At runtime?

#

Add a debug log to the spawn method to make sure it's even called.

#

And increase the verbosity of Photon

karmic dagger
wide girder
#

verbosity is logs level. Usually it's set to errors only, but we want to see what's photon doing, so set it to the lowest level possible. It should be in the Photon settings asset file.

karmic dagger
#

I can’t find the settings file

#

I went into the photon folder

#

And i have photon chat, libs, realtime and unity networking

wide girder
#

I think it's in Photon - Resources folder.

#

You can also probably get there via the menu at the top

#

You should know where it is, because you wouldn't be able to use Photon in the first place if you didn't set it up. There's App id and whatnot.

karmic dagger
wide girder
#

Take a screenshot of the unity editor window

karmic dagger
wide girder
#

Of the whole unity editor window

karmic dagger
wide girder
#

Including the top menu...

karmic dagger
wide girder
#

Is there anything photon related in the window?

karmic dagger
#

Yes

wide girder
#

Btw, I wanted to ask earlier, but is there any reason you don't want to instantiate the player prefab?

wide girder
karmic dagger
#

I have a load of scene references I can’t reference

#

If the player is a prefab

wide girder
karmic dagger
#

I can’t really change it now tho

#

Ok so pun logging is set to errors only

#

Should i set it to informational or full

wide girder
#

set it to full for now

karmic dagger
#

K

#

I have this

#

Menu for rpca

#

Rpcs

#

Would i have to do anything here by any chance

wide girder
#

No. You're not using an rpc in this case

karmic dagger
#

Oh

#

Thats the console

wide girder
#

Is that after the spawning?

karmic dagger
#

Ye

wide girder
#

Is that on the server or the client?

karmic dagger
#

Client

#

I have a room thing

#

So once the room is created

#

The player spawns

#

And then yeah

#

Thats

wide girder
#

I mean, is it on the master client?

karmic dagger
#

The console after that

karmic dagger
wide girder
#

a network event should be reflected in the logs afaik.

#

If it doesn't then your event doesn't work.

karmic dagger
wide girder
#

Ugh... I guess you didn't read the Raise event page after all..?

karmic dagger
#

I did

wide girder
#

Ok. Check the part about receiving the event again.

karmic dagger
#

But I don’t really understand what it means

wide girder
#

Then ask instead of just ignoring it...🤣

#

Do you think it's gonna magically work if you don't follow the guidelines?

karmic dagger
#

Well I copied the code

#

So I thought

#

And i just changed

#

Around some stuff like the pretab

#

Prefab

#

Gameobject

wide girder
#

Copying the code is not enough. Networking is not a beginner topic. You need to understand what you're doing instead of just copying.

karmic dagger
#

I read through what it said

#

Didn’t really understand it tho

wide girder
#

Check the final code example. Specifically the part about the implemented interface.

wide girder
karmic dagger
wide girder
#

Or learn to learn on the go. You're not gonna get far if you just copy stuff without understanding it.

karmic dagger
#

Am i even on the right thing

wide girder
karmic dagger
#

Im on the instantiation

#

Page

#

Doc

wide girder
#

If you don't understand something, google it. If you still don't understand, ask in the community. It's that simple.

wide girder
karmic dagger
#

All i find are the docs

#

To the same thing

karmic dagger
#

On it

wide girder
#

...

#

Scroll back up. I shared the relevant page twice.

karmic dagger
#

Thought we were on about this

wide girder
wide girder
karmic dagger
#

Well thats why i was confused

#

Cause u were on about a different thing

#

Ok now it makes sense im on the right page

wide girder
karmic dagger
#

I thought u were on about the raise event part

#

In the instantiation page

wide girder
#

No, I clearly said "raise event page". But anyways, you know what to read now, so go ahead.

karmic dagger
#

I read the raise event part right???

wide girder
#

yes

#

The relevant part starts with:

To receive custom events, we have two different possibilities.
karmic dagger
#

Ok so i have read it

#

What should i do from now

#

Cause im still super confused

#

On how am meant to implement this with my current

#

Code and way of making rooms and stuff

wide girder
#

Well, it tells you about 2 options. Did you read what they are?

karmic dagger
wide girder
#

Did you even read? It tells you the first option right after the sentence that I quoted...

karmic dagger
#

The ioneventcallback???

wide girder
#

the IOnEventCallback, yes.

karmic dagger
wide girder
#

Yes. You're raising a network (custom) event.

#

So you need to be able to receive it on the client.

karmic dagger
#

Damn I thought networking with photon was mean to be simple lol

wide girder
#

It is very simple

#

It just requires an intermediate+ understanding of C#, unity and coding in general.

#

You won't find a simpler networking solution.

karmic dagger
#

Isnt there that mirror thing???

wide girder
#

There is, but it's very similar to photon.

karmic dagger
#

I do know how to use it a bit

#

But can’t find out

#

This one thing

wide girder
#

The docs are there.

karmic dagger
#

Im trying to do

karmic dagger
wide girder
#

If you don't understand the docs, it means that you either don't read them properly, or miss some prerequisite knowledge.

karmic dagger
#

Because im trying to use the player from the scene instead of instantiating it

wide girder
#

Then it's probably the latter. In which case either learn that prerequisite stuff or put the networking stuff on hold, until you're ready.

karmic dagger
wide girder
wide girder
#

Besides, docs are not supposed to give you a ready implementation of a feature. You need to be able to figure that out on your own.

karmic dagger
#

So I didn’t have to write it out to save time lol

wide girder
#

That's the difference between a beginner and intermediate coder.

#

The docs are there to teach you the api

karmic dagger
#

So I decided to ask here

wide girder
karmic dagger
#

Been at this for like 12 hours now

#

So thats why

wide girder
#

Anyways, that convo is going nowhere. I'm not gonna tell you to stop doing what you're doing, but I'm not gonna spoon feed you either. Read the page, if there's anything unclear, google it, only then ask for help.

karmic dagger
#

The issue is I don’t know what im trying to do with all this like what do i need a custom event for

#

To instantiate a player

wide girder
#

I think we've already figured the part about instantiation.

karmic dagger
#

I mean control a player

wide girder
#

All you need to do is make your event work.

karmic dagger
#

What about the loadbalancing.event recived

#

Is that a better way or not really

wide girder
#

You can use any option you like.
But just a tip: don't try to avoid something you don't understand. Learn about it instead. That's the only way to improve as a coder.

wide girder
karmic dagger
#

Ok so does this code have to be inside the spawn player script or a separate script

karmic dagger
#

The one i was sending u before

wide girder
#

Your code is fine. It misses some things to receive the event though. That's why you need to learn how to receive an event.

karmic dagger
#

Oh ok

#

I could also try spawning the player

#

But i would have to recode

#

A good chunk of my stuff

#

Which I honestly dont know is a good idea

wide girder
#

You can think about refactoring later. Get the event working first.

karmic dagger
#

The issue is i have a camera in my scene and it follows the prefab but I can’t set that in a prefab it just doesn’t let me

#

And same with ui elements

karmic dagger
#

Because the game will be like cs go so ima going to have to spawn the players

#

Anyways

#

When they die

wide girder
#

If you're not gonna use an event, then there's no issue I guess..?

#

Just use the normal instantiation method

karmic dagger
#

Yeah im just confused on how I would reference all the stuff

#

That the player needs

wide girder
karmic dagger
#

Could u just tell me by any chance cause it still to do with the networking stuff

wide girder
#

It has nothing to do with networking. You'd reference objects the same way as you do in single player.

karmic dagger
#

Cause the player is a prefab

wide girder
#

What doesn't let you?

karmic dagger
#

And the camera is in the scene

#

And not a prefab

#

And if i make the camera a prefab that causes the ui to not be a prefab

wide girder
#

You'd need to assign the references at runtime after spawning the object.

karmic dagger
#

And then doesn’t let me

karmic dagger
#

I mean gameobject

wide girder
#

As I said, I've no intention of spoon feeding you and this kind of questions are certainly not for this channel.

karmic dagger
#

Im just going to make a prefab for everything i want to reference

#

And hopefully that works

wide girder
#

That's probably not gonna work as you expect... Knowing how to reference things at runtime is one of the basic things you need to know to make a game(even just a single player game). I suggest you go to unity learn and to the beginner pathways.

karmic dagger
#

I don’t think i have explained what im trying to do here

#

Clearly enough

#

Thats my bad

karmic dagger
wide girder
#

Networking related?

karmic dagger
#

Yeah

karmic dagger
#

I really dont know whats going on

wide girder
karmic dagger
#

So i have a orientation gameobject on the player determines were the player is facing and when the player is spawned everything is off when i press w he moves to the right

#

And everything is fine

#

Something to do with spawning???

#

Im using quaternion.identity

#

And a regular vector 3 for the spawning position

wide girder
karmic dagger
#

It is

#

Because when the player is in the scene its fine

#

And when spawn by the network not

#

Ok fixed it

#

My cam was not being assigned

wide girder
#

So it was not networking issue after all

karmic dagger
#

It was

#

With the player spawning

wide girder
#

You said that your cam was not being assigned?

#

that has nothing to do with networking though.

karmic dagger
#

Yeah im not to good at explaining stuff

karmic dagger
wide girder
#

Okay. I'd say it 25% relevant to networking

karmic dagger
#

Anyways now there is a even worse problem

#

I built the project

#

And when the second player join

#

S

#

Everything just goes mental

#

The 2 player sees themselves in 3rd person

#

The 1 player can move his camera

#

Everything is fine untill the second player joins

wide girder
#

Sounds like you're not handling the controls for each player separately.

karmic dagger
#

I am

#

Im using a photon view

#

And then the movement is in if(photonview.ismine)

wide girder
#

Well, you probably forgot it somewhere, seeing how player 1 can control player 2 camera.

karmic dagger
#

No nobody can control the camera

#

I have a move cam script which follows the player

#

Should that be if view.ismine to

#

Or not

wide girder
#

Depends. I've no clue what you're doing there and how it's following

karmic dagger
#

Transform.position = player.transform.position

#

Thats it

wide girder
#

and you're sure player is referencing the correct thing?

karmic dagger
#

And there are 2 players

#

Trying to use that 1 camera

wide girder
#

if it's not controlled via networking and has proper references, it shouldn't be a problem

karmic dagger
#

Yeah but when 1 player is spawned

#

I have a var player = photonnetwork.instantiate

#

And the cam follows player.transform

#

Could that be causing issue or no

wide girder
#

just to make sure: you're spawning the player in your camera script..?😅

karmic dagger
#

The player is spawned with a empty game object

#

In the scene

wide girder
#

Then when is the camera player field assigned?

karmic dagger
#

That has a playerspawn script on it

karmic dagger
#

The var

#

Player

wide girder
#

Share the code then

karmic dagger
#

All

wide girder
#

If you can only share the relevant part, share the relevant part.

karmic dagger
#

If u want me to shard with gdl space il do all

#

Screenshots i can do the relevant part if u want

#

I rather do all tho

wide girder
#

Share the whole code then

karmic dagger
#

Because then u can see the veriables

wide girder
#

You said you assign the camera Player field via code, but I don't see it anywhere in the code.

#

aah

#

nvm

#

Each time you spawn a player you assign the new player's PlayerTransform

#

So the camera would follow the last player you spawned

karmic dagger
#

That

#

With photon???

wide girder
#

You already do it.

#

And that's the source of the issue

#

And it's not networking related

karmic dagger
#

It related to the player spawning right???

wide girder
#

When you spawn the first player, the camera references the transform of the first player

#

Then when you spawn another player, it references the transform of the other player

karmic dagger
#

How would i do that???

wide girder
#

YOU ALREADY DO THAT

#

That's the issue. The camera(regardless of what client it belongs to) references the same player.

karmic dagger
wide girder
#

Make it so that each client camera references that client's player

karmic dagger
#

That what im trying to figure out how to do

wide girder
#

Either keep a list/array of players and make the camera pick their player from the list or add the camera to the prefab, so that it always references it's parent

karmic dagger
#

Can’t do the second option for a few code reasons

#

The fist one il tru

#

Try

karmic dagger
#

How do i get the players photon id

wide girder
#

Google it. Look through the photon docs or watch some tutorials. It feels like you've zero idea on how to use photon.

karmic dagger
#

Have any idea about photon

#

This project is so i can learn some more stuff about it

#

I made one before but that was just to see

wide girder
#

And this is not the place for a photon basics lecture. There're enough materials for that online.

karmic dagger
#

It was to just see how some stuff work

#

And now trying to make a propper game with it

karmic dagger
wide girder
#

As I mentioned before, with intermediate + topics like that you wouldn't get an exact solution to your problem, you have to use docs and tutorials to understand how things work. Then use your own head to find a solution.

#

As for getting player's(or rather photon view) id, it's definitely in the docs.

karmic dagger
wide girder
#

Although, in this case, you probably don't even need the id at all.

#

You only need to know what player belongs to the current client.

karmic dagger
#

Anyways thanks for all the help and putting up with all my stupid photon beginner questions

low spoke
#

hello im using netcode system and i want to spawn objects as client how could i do it?

high rose
#

You should send a server RPC from the client to the server that tells the server to spawn it

summer anchor
#

getting the following error

(0,0): error <FirePistol>g__ShootServer|20_1 must not be static (at System.Void Pistol::<FirePistol>g__ShootServer|20_1(System.Int32,UnityEngine.Vector3,UnityEngine.Vector3))

from this line of code

ShootServer(pistolDamage, cam.transform.position, cam.transform.forward);

What does it mean exactly?

patent fog
#

It complains that your method is static. Is it ?

summer anchor
#

not sure what that means xD very new to unity, this is what it calls

   [Command(requiresAuthority = false)]
         public void ShootServer(int pistolDamage, Vector3 position, Vector3 direction)
         {
            if(Physics.Raycast(position, direction, out RaycastHit hit) && hit.transform.TryGetComponent(out Player enemyPlayerHealth))
            {
               enemyPlayerHealth.playerCurrentHealth -= pistolDamage;
            }
         }
#

it also doesnt like me having "public" at the start of the command

patent fog
#

Well the method itself is not static, that's one thing. Otherwise would be declared as public static void ShootServer()

summer anchor
#

"The modifier 'public' is not valid for this item"

patent fog
#

🤔 is it unhappy with the Physics.Raycast() static call then maybe ? Not sure

summer anchor
#

not sure, was following a guide but its using fishnet not mirror, all ive changed is [ServerRpc] to [Command] and put using; Mirror; and network behaviour

summer anchor
#

very very fresh at unity, just mixing and mashing a heap of guides, pretty happy with where im at, just need to work out the whole shooting side of things now

#

wasnt going to go the bullet object and was gonna use raycast and trails instead

patent fog
#

Mirror requires yur Commands to start with "Cmd"

#

so try public void CmdShootServer(

summer anchor
#

Thanks, still the same issue though, doesnt like public

patent fog
#

lol what ?

#

where is the method, can you show the surrounding code ?

#

probably didnt close a bracket or something like that

summer anchor
#

wow

#

im an idiot

#

i see it now xD

patent fog
#

No worries, just next time use a paste site for big blocks of text

#

Yeah your method is declared inside FirePisotl ^^

summer anchor
#

yep hahaha

#

was looking at it for ages, and just noticed it once i pasted in here... rip

patent fog
#

Happens a lot in the beginning, making sure your file is well formatted helps ^^

patent fog
#

Back to your original issue, is it solved now ?

summer anchor
#

Will do, thanks for your help mate

#

yeah theyre all good now

#

time to test if it works 😂

patent fog
#

Alright 🤞

summer anchor
#

once this is sorted, time to add some giant spiders 😂 getting excited

delicate parrot
#

(Experienced in c#/unity but 0 in networking)

civic flicker
#
[SerializeField] private GameObject player;
    [SerializeField] private Rigidbody2D rb;
    [SerializeField] private Vector3 directionToPlayer;
    [SerializeField] private float moveSpeed;
    [SerializeField] private bool spottedPlayer;
    // Start is called before the first frame update
    void Start()
    {

        spottedPlayer = false;
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void FixedUpdate()
    {
        if (spottedPlayer)
        {
            player = GameObject.FindGameObjectWithTag("Player");
            directionToPlayer = (player.transform.position - transform.position).normalized;
            rb.velocity = new Vector2(directionToPlayer.x, directionToPlayer.y) * moveSpeed;

        }
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            spottedPlayer = true;
        }
    }

Hello, I'm trying to make it so the enemy follows the player that triggers it, but my prefabs all have the same playerID, which means that no matter what, the enemy will only follow one player, is there a way to go around this? (im using Netcode)

neat veldt
#

also you should not be using FindGameObjectWithTag in an update loop

civic flicker
#
[SerializeField] private NetworkObject player;
    [SerializeField] private Rigidbody2D rb;
    [SerializeField] private Vector3 directionToPlayer;
    [SerializeField] private float moveSpeed;
    [SerializeField] private bool spottedPlayer;
    // Start is called before the first frame update
    void Start()
    {

        spottedPlayer = false;
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void FixedUpdate()
    {
        if (spottedPlayer)
        {
            player = NetworkManager.LocalClient.PlayerObject;
            directionToPlayer = (player.transform.position - transform.position).normalized;
            rb.velocity = new Vector2(directionToPlayer.x, directionToPlayer.y) * moveSpeed;

        }
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            spottedPlayer = true;
        }
    }
}
#

i've been trying to use networkmanager.localclient now like the docs say

#

it worked but the enemy object wasnt syncronized

#

i tried adding a networktransform to the enemy and the problem still perstists now

neat veldt
#

that will only get the local player?

#

and not the one who triggered it

civic flicker
#

how do i find the player id?

#

yea i want to get the id of the player who triggered it

neat veldt
#

I think you can get it from NetworkObject

civic flicker
#

ill give it a shot

#

thanks!

neat veldt
#

np

patent fog
delicate parrot
#

thanks ❤️

civic flicker
# neat veldt np
void FixedUpdate()
    {
        if (spottedPlayer)
        {
            player = GetNetworkObject(4);
            directionToPlayer = (player.transform.position - transform.position).normalized;
            rb.velocity = new Vector2(directionToPlayer.x, directionToPlayer.y) * moveSpeed;

        }
    }
#

i was able to make the enemy move towards that object id(4)

#

but the problem is this is hard coded

neat veldt
#

i was thinking more like

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            player = other.gameObject;
            spottedPlayer = true;
        }
    }
```why do need the id?
#

just set player to the other gameObject in the trigger logic

civic flicker
#

hmmmm okay ill try that

civic flicker
#

its giving me this error

#

NetworkObjects always give a shit ton of errors

uneven frigate
#

I started using WebSocket system for my multiplayer demo, I can send message client to server but how can I send a variable or something else server to client?

neat veldt
#

change [SerializeField] private NetworkObject player; to [SerializeField] private GameObject player;

#

i think you are missunderstanding networkobjects

civic flicker
#

i think so too ffs

neat veldt
#

they're really only there for the backend system

#

you rarely have to interact with them

civic flicker
#

oh i see so its more for the package than for me

#

backend*

neat veldt
#

ye

civic flicker
#

okay i changed the object type ill make another build

neat veldt
#

also check out ParrelSync

#

then you dont have to build to test your game

civic flicker
#

ohh really

#

gotta try that

civic flicker
#

why isnt this shit working omfg xD

#

been trying to fix this for 3 hours now

#

the enemy doesnt respond to the host now

patent fog
#

On the client you would also need a websocket library to be able to connect to server, send data, and receive data

#

based on what you're saying you already have a client though

civic flicker
#

thanks for the help man

#

really grateful

summer anchor
#

How can I get the netid of each player so when I damage someone I can run a client rpc to tell everyone they got damaged

#

trying to use this

void RegisterPlayer()
{
  if(isLocalPlayer)
  {
    string _ID = "Player number " + GetComponent<NetworkIdentity>();
   transform.name = _ID;
  }
}
#

with mirror

patent fog
#

[ClientRpc(includeOwner = false)] void RpcRegisterPlayer() will execute the method for every client except the owner

summer anchor
#

it doesnt seem to be getting the networkid number

#

which i need to use for a lot of things, damage, health, score etc

olive vessel
#

NetworkIdentity has a netId variable, surely you want to add that to the string instead?

summer anchor
#

yeah sorry i have .netId as well at the end

#

just been following a video, although he isnt using mirror so im trying to work out how to make it work