#What are the NFGO Conventions?

1 messages · Page 1 of 1 (latest)

dense magnet
#

To start off: I know the concepts and how networking works. I'm not in the loop on how the framework is typically used, and most resources online don't really go into much detail beyond the conceptual "how it works" and a basic example of networked player movement. I've skimmed the casual coop example project but it isn't exactly what I'm looking for. I'm just wondering what the conventions for a host-client game typically are (for example, Lethal Company since it is made with NFGO).

and by conventions, I mean things like how authority is distributed, how the code is structured (Player.cs or PlayerServer.cs and PlayerClient.cs?), how much to handle on the server and how much to give to clients, etc. For example, how would one typically approach a system where a player can have three items in their inventory, and an item can either be held in hand, stashed in inventory, or dropped on ground? would it change ownership when picked up? The player holding it would have it at some position for their view model, while others will see it in their third person hand, so this would have to be considered.

deep canyon
#

There are a few topologies that NGO can use. By default it uses a client server model. The server/host will have authority over all in scene network objects. Clients can request ownership of any object but there can be only one authority of an object at any given time.
You can change ownership when reparenting a network object but it's not necessary.

You can structure your code however you like. There are no rules regarding it. I like to keep all player logic in one class. But some of the Unity samples will split things between client and server classes.

Also check out the new Attachment helper components that facilitates reparenting network objects
https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.5/manual/components/helper/attachablebehaviour.html

dense magnet
#

I know theres no rules but theres typically conventions for what works best agreed upon among experienced users, so I was just wondering about that

dense magnet
#

also situations like, say i have a system where i can connect wires together, and machine A is connected to machine B with a cable

#

when a client joins the server, how is this sort of thing typically synchronized

#

at the moment I have an Identity network behavior with some static logic for getting and storing identities, and when synchronizing, it would deserialize machine A's identity to derefence machine A's gameobject, and then the same for machine B, then connect them from there

#

but this feels hacky and there has to be a better way to synchronize

sick plaza
deep canyon
dense magnet
#

actually now that i think about it, most of my confusion comes down to just how much of the game state the client really needs to know

#

like obviously state machines under the hood that control enemy behavior can probably be left out

#

for a client it really just has to "look right"

deep canyon
dense magnet
#

yeah, i guess a network animator + network transform + network rigidbody if needed sorta do most of that for you

#

i was just thinking about a hypothetical monster system where they can chase you and attack you

#

the client doesnt need to know the monsters state machine, pathfinding, or anything of the sort

#

just its location and animation

#

and sounds i guess

deep canyon
#

For the most part yea. There could be client prediction systems that might want to simulate NPCs locally

dense magnet
#

item systems are just evil in networking, lol

#

my system cant make the compromise of just deleting the dropped item and creating a view model

#

since the objects are functional both in hand and dropped

#

so i have to toggle the network transform when it is held

deep canyon
dense magnet
#

oh yeah i totally missed that, thank you

dense magnet
#

is the example project used for the attachment system guide available somewhere?

#

its just not working quite how i expected it to and i was wondering how the example handled rigidbodies

#

since i cant disable the rigidbody

deep canyon
dense magnet
#

local scale too apparently lmao

deep canyon
#

Yea. I keep the node at a scale of 1

#

Or you can scale and position the node differently on local player if your game is 1st person

dense magnet
#

do you know of a general solution for switching between the world and attached view for references? for example, a light on a flashlight, switching between whether the world or attached version of the light is controlled by the flashlight script

#

sorry for all the questions lol i just dont want to "figure things out myself" and come up with a backwards solution when theres an easier approach that everyone else does

#

i have an overcomplicated solution of like

#

SwitchableVariable<T> where T is like the light or something

#

and in the inspector it would have properties for the component controller, world light, and attached light

#

i always somehow find myself pushing the limits of unity trying to solve simple problems like this

#
    public class SwitchableValue<T>
    {
        [SerializeField]
        public ComponentController controller;
        [SerializeField]
        public T onValue;
        [SerializeField]
        public T offValue;

        public T Value => controller.EnabledState ? onValue : offValue;
    }```
#

dont even know if generics can be serialized like this

#

oh lol it totally can

#

that worked like a charm so nvm lol

deep canyon
#

This attach system is weeks old so we are the pioneers of it

dense magnet
#

i see

#

this class gives this in the inspector

#

and you can just do like

#

light.Value to get the active one

#

its not too pretty and im sure theres a better way to handle this sort of thing that doesnt involve the duplication of components