#archived-code-advanced

1 messages · Page 56 of 1

zealous wasp
#

Hey! I have a question about Native Containers on Jobs. Can i somehow make the container read-only for multiple jobs at the same time, given that i do not edit them, i just read those. For example i need to start 2 or 3 jobs at the same time reading from a single NativeArray, can i achieve this, or is this simply not possible?

bleak citrus
#

that should make the safety system happy, ye

zealous wasp
#

Thanks

desert scroll
#

i have a question about inheritance

#

i have FunkyA, but i want a more specialised SpecificFunkyA that effectively inherits from FunkyA and SpecificABase

#

the only way i can think of doing it is by having ABase and SpecificABase to be interfaces rather than classes

#

but i want to specify functionality in them

#

obviously made up names but i hope ive gotten my point across

sly grove
desert scroll
#

I was afraid of that

#

composition feels like it'd be messier

sly grove
#

What you want is a GameObject that has a FunkyA and a SpecificABase as separate components

tropic vigil
# desert scroll

A class can inherit only from one class, but it can additionally implement multiple interfaces. I would suggest changing at least one class to an interface.

sly grove
#

composition is much better than polymorphism in Unity

desert scroll
sly grove
#

Composition is always an option

desert scroll
#

I could potentially make SpecificABase into a ISpecific interface and then just have my SpecificFunkyA inherit FunkyA and ISpecific

#

But it feels like a cop out as then can't add functionality to the now gone SpecificABase

sly grove
#

maybe - hard to say with these placeholder names etc

desert scroll
#

Yeah yeah ok I'll give the actual concrete examples will be easier 1 sec

#

i got
ConstructObject : MonoBehaviour
ConstructCore : ConstructObject

these optionally have a ConstructMovement they reference

#

i need the ConstructCore to have* a ConstructCoreMovement : ConstructMovement and the ConstructObject to have a ConstructMovement

#

this is all fine for now

#

however i want a HoverMovement : ConstructMovement

#

and then consequentially a CoreHoverMovement : HoverMovement, ConstructCoreMovement which is the issue - i cant inherit from both

#

a Construct being the player controlled "thing" i guess made up of parts

sly grove
#

Seems like you could/should have these separate components:

ConstructIdentity
ConstructMovement
HoverMovement : ConstructMovement```
desert scroll
#

whats the ConstructIdentity thing

sly grove
#

maybe should be called ConstructObject

#

just

#

whatever the basic things it needs to be recognized as a "Construct"

#

not sure what a construct is in your game so I'm kinda guessing at what you need here

desert scroll
#

right sorry shouldve gone higher up

i got a Construct which references a ConstructCore
this core can then in a tree structure reference ConstructObjects with some other stuff

each of the objects in this structure may have a ConstructMovement, which gets sent up to the top level in some priority based system

i need the movement on the core to have additional core specific functionality

sly grove
#

Is this like.. Kerbal Space Program style vehicle construction?

#

Or Space Engineers

desert scroll
#

1s

#

ill hack it to get it running and send a clip

#

(currently i have the HoverMovement just implement ConstructCoreMovement and have it sort of figure out which its on but thats not good at all)

#

the idea being the crystal is a core which needs a core movement which will provide the animation / logic for making it fly into something else

the rock is an object which just wants a normal movement, and because its not a core i dont want the core specific logic for making it fly into something else

#

and as you can see each object or core in the scene can have its own movement, which using some priority or other logic the construct will choose between

#

but obv i want the core movement disabled when its in something

#

extra complications come from wanting runes to be able to provide movement for the construct but thats a later issue

desert scroll
# desert scroll

but back to the original thing, hopefully this gives a bit more context

desert scroll
#

mb

bleak citrus
#

composition over inheritance (:

desert scroll
#

if it helps this is the issue - i need CoreHoverMovement to be a HoverMovement and CoreMovement

#

current solution is for HoverMovement to inherit CoreMovement and have it figure out if its a core or not but thats dodgy

#

ty so far everyone for help, i realise this is alot of spam dont mean to fill up the channel

bleak citrus
#

yeah, this is why inheritance falls apart in a lot of situations

desert scroll
#

for more specifics
HoverMovement handles making the object float, move, and aim
CoreMovement requires some functions for implanting the object and has some functionality

bleak citrus
#

you have Animal and Flyer and Walker

#

and then, oh no, I need an animal that can fly AND walk

desert scroll
#

yeah

#

and Flying and Walking dont affect each other

#

the only way i can think of doing it with composition is this

#

CoreAttacher is just generally "the extra things a core needs to do that is Movement specific"

#

the issue is then it seperates the HoverMovement and the HoverAttacher - I could have the HoverAttacher point at a JumpingMovement for example which is bad and wrong

hybrid belfry
#

Is there any way to run an Update() method constantly in the Editor? I need to check if the position of a movable transform has changed. If it has, do something

bleak citrus
#

that's what [ExecuteAlways] is for

hybrid belfry
#

Yeah so I had that idea originally by using ExecuteInEdit mode which is ideal. I also thought it would be a great idea to put it under a new class, so the main class didn't have to make use of a constant update method. The functioanlity will only be related to this new class

#

The problem I have is, I need the Serializable list to drag and drop Transforms. Without inheriting from MonoBehaviour, this is fine. However, I need Mono so I can make use of the Update() method. Problem then is I can't view the List in the Inspector for some reason :/

bleak citrus
#

ExecuteInEditMode only applies to MonoBehaviours

#

You could have the Update() method bail out early if it's in edit mode

hybrid belfry
#

Hmm yes i see. Is it possible to serialize in with Mono?

sly grove
#

you can't just make a class a MonoBehaviour with no other changes to how you treat it

hybrid belfry
#

Yes I see. I took this root as I thought there's no way to ExecuteInEdit for just a method such as Update() - I don't want to always execute all parts of the class

fresh salmon
#

@eager verge - Not sure why you deleted your message
You might be getting errors, you need to install the Android Logcat package so you can see them on your computer while the game is running on your phone (works via the USB debugging feature).
In the meantime, code review:
Disposable types like Stream, MemoryStream should be used inside a using statement to ensure that the object is properly freed, even if an exception occurs.
You can use responseStream.CopyTo(memoryStream) instead of the loop to copy stream contents

eager verge
fresh salmon
#

A few minutes ago, you posted a link to your code of yesterday

#

Something like

Can anyone help with this? <link here>

eager verge
#

oh yeah i see. I didnt do that. Maybe the server did?

fresh salmon
#

Yeah maybe, seems like the last Discord update made it slower, I sometimes have freezes when I type

bleak citrus
#

it does seem to be happening in other places too

#

but i swear it started when i joined here (it IS a very large server...)

hybrid belfry
undone coral
#

does anyone know how to call plugin (C++) or even burst code the exact moment a camera has finished rendering?

desert scroll
desert scroll
#

sorry didnt finishthat message - was gonna ask your opinions on it all

sly grove
#

Can ObjectMovement not expose whatever it needs to expose via public Methods / Properties?

desert scroll
#

ObjectMovement has stuff for IsTransitioning, IsActive etc

#

and some SetTransitioning and SetActive functions

#

which i want to keep relatively internal

#

the SetTransitioning one specifically

#

in this case of the hover its relatively benign in that they are all i need - they could prob be public

#

but in the future i feel i may need more access to specific features of the ObjectMovement, and moreso the specific internals of the matching ObjectMovement

#

e.g. a LegObjectMovement and a LegCoreMovement

#

if c# has a friend thing would that work?

sly grove
#

All of that can be handled through ObjectMovement's public API

#

by which I mean its public members

desert scroll
#

right yes, however i may want my hover core movement to change the hover height or some other private variable, which i dont want any other class to get to

#

or in the leg one, i may want some private methods and functionality to enable and disable specific legs, which i want to keep internal and private and called by the other movement functions
in which case the core movement for the legs (as i would probably want a core to be able to have this moveset) would need access

#

to me inheritance solves these issues 1 for 1, but the the multi inheritance issue from before comes back

#

oh

#

i can make it a nested class

#

but idk if i would then be able to add it as a component

sly grove
desert scroll
#

well LegMovement would inherit ObjectMovement cos it would be able to go on anything
but id need a CoreLegMovement for handling Core specific movement stuff like attaching and detaching from whatever

#

which would inherit CoreMovement

#

but i need CoreLegMovement to access internals of LegMovement, which makes sense to be an inheritance thing but then ye

undone coral
sly grove
undone coral
#

it sounds like you are discovering that platformer movement code is tightly coupled

#

all of the movement behavior and input for platformers, it's all tightly coupled

bleak citrus
#

yeah

desert scroll
# sly grove oh see I'm not sure I understand what CoreMovement is vs ObjectMovement

right yes sorry - ObjectMovement basically allows you to call Move() and Aim() on a thing and controls an object, (makes it hover, or walk, or hop) and control as youd expect

CoreMovement is tightly joined with a specific ObjectMovement, and is for allowing a Core to attach / detach from some other object
currently its just these 2 bits but may need more in the future

desert scroll
undone coral
#

it is not possible to make this decoupled and extensible. you would disguising a tightly coupled method by spreading it out meaninglessly over bits and pieces of classes, and recreating the idea of a method by putting order and/or various state flags on these different classes

#

@desert scroll does that make sense

desert scroll
#

mb sorry, dont see what youre suggesting

undone coral
#

based on the screenshot i saw, it looks like you move a character with with a joystick, who has the capability to become physics-driven-joined to other objects

desert scroll
#

yes effectively

undone coral
#

and you want to seemlessly transition between different kinds of movement too, like hovering, X and Y

#

this is all very, very tightly coupled

#

i assume you want this to feel good

desert scroll
#

well, different objects can have different movements

#

hence the decoupling

undone coral
#

you can certainly put a class on an object that says what kind of movement it will have

desert scroll
#

and some movement types can be used by a core, hence this debate currently

undone coral
#

but the actual behavior will probably live in one class

#

that is what i'm saying. it is indeed a tightly coupled big giant class

desert scroll
#

what do you mean 1 class

undone coral
#

you will write a class called TomsterPlatformerMovement

#

and it will deal with the translation of inputs to movement and physics in your game world

#

and the different kinds of objects it can move

desert scroll
#

really? i dont think so

undone coral
#

it will be just 1 class

#

well

desert scroll
#

e.g. this is hover

undone coral
#

what i am trying to tell you

#

is that you are already doing this

desert scroll
#

this is hop

#

they are very different things

#

and no reason to be in 1 class

undone coral
#

i am trying to tell you it is already one class

#

you havev just spread it out, for only increased bugginess and complexity, across multiple classes

#

i'm not saying you can't do this

#

you can. you can make your code worse

#

i am not stopping you, and you can prove to me that you can do an already hard thing even harder

desert scroll
#

are you saying they should both be in the same class and have an if statement around each them?

#

and thats less error prone?

undone coral
#

i am not writing this for you

#

i am saying you are already doing that

#

but in different classes, for the aesthetic experience of having multiple classes

desert scroll
#

no but, im just trying to understand your view point as i am sure you have a valid set of reasoning i just dont get it yet

undone coral
#

which is a legit instinct to follow in all cases EXCEPT when you are trying to make movement for platformers

#

you have spread out your if statements across classes

#

using the type system

#

for no gain

#

you will almost certainly have a if (movement is HopMovement hopMovement) somewhere

#

you are checking types somewhere, i am confident

#

right?

desert scroll
#

nope

undone coral
#

you have at least one 1 somewhere that uses is

#

then you will have bugs

desert scroll
#

this is the top level Construct class

#

references an ObjectMovement

undone coral
#

if you are not going to have an is in this approach

#

you are going to reinvent is

#

which is even worse

#

to deal with bugs

#

you are already in some sort of jeopardy

#

i don't even know what issue it is you are trying to fix yet

#

it isn't clear

#

like is there something broken?

#

that you are trying to improve?

desert scroll
#

i can explain that in a sec, just want to understand youre on about with the is issue

desert scroll
#

wdym

undone coral
#

if you are going to spread stuff out across a class hierarchy

#

somewhere, something is going to need to leak a little out of your abstraction

#

one way that can happen is using is

#

like you and i don't decide if it's tightly coupled, the problem does

#

does that make sense?

#

you cannot will this thing to not be tightly coupled

#

unless it is not important that the movement feels good

desert scroll
#

yes i get what you mean, but i dont think this is tightly coupled in the way you think

#

the issue youre referring to is solved directly with inheritance and interfaces right

undone coral
#

i think i'd need to know what your actual issue is

#

to be helpful

desert scroll
#

then all you need is an interface saying theres a move() function and the top level doesnt care how it happens

#

the issue itself is an aside to all of this

undone coral
#

what is the issue?

desert scroll
#

I have a Movement class that looks like this

#

and then a HoverMovement, HopMovement, in the future many other movements

undone coral
#

i'm saying what is going on in the behavior

#

that is buggy right now

desert scroll
#

its effectively an interface with some base functionality

#

that all works great

undone coral
#

you're saying there are no bugs?

desert scroll
#

not in any of that na

undone coral
#

i feel like i can find a bug in this pretty quickly

#

like by playing with it

desert scroll
#

1 sec lemme explain the issue im having

undone coral
#

okay

desert scroll
#

the ConstructObject has a derived class of ConstructCore which wants extra functionality out of this Movement class, concretely a way of attaching and detaching

#

this is obviously gonna be dependent on the matching ConstructObjectMovement

#

initially my approach was for ConstructCoreMovement to inherit ConstructObjectMovement

#

however here is the issue

#

i sent this earlier too

#

i want a CoreHoverMovement

a class with the functionality of the HoverMovement
but promises extra functionality that the Core can use

undone coral
#

you can create a class CoreHoverMovement that contains two fields, one referencing a CoreMovement and the other a HoverMovement

desert scroll
#

so a core still needs a ObjectMovement to be able to move around, just also wants to be able to call Attach and Detach and have this be specific to the type of movement it has

may have a hopping Core, whose attachment is to jump in the air then dig into the thing
or hovering Core, which is the video i showed

undone coral
#

and i suppose you can put in a bunch of logic in it

#

you can make things easier by making this simpler and not trying to spread out this behavior

#

which is kind of my point

desert scroll
undone coral
#

well. like i said

undone coral
#

this stuff is tightly coupled

#

in order to build that class, you are doing is

desert scroll
#

what is coupled with what sorry?

undone coral
#

okay

#

let me put this differently

#

you are writing a giant method, whether you like it or not

desert scroll
#

containing what

undone coral
#

it doesn't have to be a giant Update method, in fact it can be evented

#

the thing that translates user inputs into movement in your game

desert scroll
#

right ok

undone coral
#

you are writing a giant method

#

it's already happening

#

right now, you have spread out your method into bits and pieces

desert scroll
#

that is 1 way to describe inheritance, but yeah sure

undone coral
#

into this elegant hierarchy

#

no

#

i am only talking about your problem

#

i am not describing inheritance

desert scroll
#

right the core / object thing?

undone coral
#

i am only talking about what you have done to approach translating player inputs into game movement

#

yes

#

you have celebrated in the elegance of this approach

#

but it is not complete

#

and in order to complete it you are going to have to finally, maybe now, use a thing in an ordinary method that doesn't exist in a class hierarchy

#

and you have no idea how to do that and neitehr do i

desert scroll
#

right

undone coral
#

if i were you... use a method.

desert scroll
#

what

undone coral
#

who knows what idiosyncratic reason you've managed to get this far

#

do you see what i mean?

#

it's just good luck

desert scroll
#

...there are methods at the bottom

undone coral
#

it was always not the way to do platformer movement

desert scroll
#

theyre just seperated into meaningful sections, it just felt like semantics was holding me back

#

and it is only because the physical objects in my game all have distinct movements

#

if 1 character in my game was able to do all of these things then yeah sure

#

but ive got control of 2 distinct things, they have 2 distinct behaviours and therefore 2 distinct classes

#

it doesnt make sense to have this in 1 class?

#

i do want to understand what youre saying, im sorry if it seems like i dont

#

its just to me it seems like youve come in and said oop bad and said good luck

#

i appreciate your help tho

undone coral
#

i think your game looks really cool btw

#

that's why i'm so excited to see you thrive lol

#

yeah

#

i feel you

#

i'm trying to think out to solve this well lol

#

1 class may be an exaggeration, but it is certainly mean to be a call to action

#

like what can you do / what tools do you need

#

to express what you need in the body of method

#

so that it's a lot simpler

#

in the right ways

#

that's not saying much

#

but method overloading has its limitations

#

in my experience doing that approach, you wind up with composing two classes into one class, and creating way more overloaded methods

#

to deal with all the edge cases

#

it's like writing an if statement across the type hierarchy

#

methods already have if statements

#

if you can do all the movement functionality imperatively in a function it's easier

#

this is why i personally use async wherever possible, it is even better than the mindfuck of the reactivex (unirx) code i used to write and advocate for

desert scroll
#

right so the less convoluted way would be for the hover movement class to also have the core functionality (attach detach), and if statement what type of object / core it has (so cant attach if only an object and not a core)?

#

doesnt that introduce a type check which is like rule number 1 dont do ever

#

the dreaded is check you mentioned

desert scroll
#

and that is the point?

undone coral
#

hmm maybe i can give an example

#

well

#

i have to think about this more

undone coral
#

maybe what is going on here, like trying to combine these two complex movement behaviors

#

like if you did it with delegating between two instances

#

i don't know... you'll end up moving a lot of code around and maybe actualyl it will get better

#

maybe you do need a "class with a bunch of static methods that can be used for composing movement behaviors in the framework you already have"

#

so i would maybe just shuffle out the valuable part of the hover and core movements into something stateless, and then you can use it where you need in a corehovermovement

#

without it needed to actually inherit from either coremovement or hovermovement

#

does that make sense

desert scroll
#

i understand what youre saying

#

as an additional thing, in the future i may need this CoreHoverMovement to have different functionality based on what it is attaching to

undone coral
#

whatever is really valuable and tricky in your game maybe move into stateless methods, which you can do with refactoring flawlessly in your IDE

#

yeah

desert scroll
#

e.g. carefully move to the centre of some contraption

#

howevever that would be handled as an if statement in the Core half of the hover code

undone coral
#

yeah

#

so that would also move into "a stateless method" and core and hover and whatever else can provide the state for it. sometimes what i do in my code that works like this is create e.g. an IPositionContext which instead of implementation-detail leaking things like Move and StopMoving it has Begin and End

#

if that makes sense

#

and i have a RigidbodyMovingContext : IPositionContext and a TransformMovingContext : IPositionContext

#

and an IPosition doesn't require you to know how any of that works. it is methods that are always called at the same times in your larger method or whatever

#

that's basically virtuals

#

the difference is you don't have to inherit anything

desert scroll
#

a more concrete error i hit a while ago which spurred my initial frustrated cry for help

i have a canUse boolean on the base ObjectMovement which basically says whether the movement can be enabled or used or whatever, and could be to do with not having enough objects in your construct or whatever

however core movement needs to override and extend this to also block it if the core is attached

my issue was when getting canUse on a hover that is just for Objects it would try and get the CoreMovement version of this function (because ObjectHover extended CoreMovement) and it would throw issues

i realise that may not be immediately understandable but just thought id give the context

undone coral
#

this is totally valid

#

my issue was when getting canUse on a hover that is just for Objects it would try and get the CoreMovement version of this function (because ObjectHover extended CoreMovement) and it would throw issues
yeah i think a library of stateless functions will solve this

#

a lot lotta games have that

desert scroll
#

looked something like this

#

in the CoreMovement when it derived ObjectMovement

#

another thing is that a CoreMovement has to reference a single ConstructCore, whereas an ObjectMovement does not have any requirement of referencing any objects and is derived class dependent

#

so i may have some SnakeMovement in the future which references multiple Objects, which obviously can not be a CoreMovement

#

thats another one of the reasons for the approach ive gone for

#

if i had a big array of static methods eg

HoverMove
HoverAim
HoverJab
HopMove
HopAim

that just feels like incredible messy

#

what if i need a Hover thing to keep reference to some particle generator?

#

passing state to a static function feels like a complete regression

fair plank
#

Hello, I've been learning how to save files using this video playlist by Trever Mock. https://www.youtube.com/playlist?list=PL3viUl9h9k7-tMGkSApPdu4hlUBagKial
In his videos he has 3 separate save slots using folders with a Json file inside, where he loads all of them at the same time to show the statistics on the menu screen.

The system I'm creating in my game is a bit different, because I am making a diary app: I have several diaries that each contain their own daily entries. When I open a diary, I want to load the most recently written page but if I press some arrows I can flip through previously written pages. Every diary page can be decorated with images and writings, so I need to be able to load only the decorations of the page you're looking at. Every page has a save file whose name is the date of when the page has been created.
How can I create a saving system where I load the diary page files by taking them from a folder? I don't want to load all of them at the same time, but only the file of the page I'm currently looking at when I open the diary and flip through the pages.

desert scroll
patent bear
#

Save & Load System

mellow plinth
#

Why even if I use RuntimeHelpers.PrepareMethod, in the profiler I can see Mono.JIT in that specific method?

main pawn
stark acorn
#

correct me if I'm wrong but seems like

[Preserve]

is only for guarantee this certain block that had been marked with it won't get stripped,
so if that's the case then what's the whole point of it?
since let's say if I'm using Reflection, but the actual code I wrote did get preserved, but not the reflection itself inside somewhere else

#
because currently my issue is some of my code that used Reflection got stripped after build
modest sparrow
#

I am curious, has anyone found a use for Records (or RecordValues) that's not covered by scriptable objects?

sage radish
mortal gust
regal olive
#

For iOS, can you create a dynamic library of the code of a Unity Game? and then load it in runtime? For Windows I create an asset bundle of the dll and then do assembly.load. But I dont know how to do something similar for iOS.

sage radish
regal olive
sage radish
jaunty creek
#

[General Question] How do people go about making AI for gridbased combat? Do you train a neural network?

jaunty creek
#

FSM?

dusty wigeon
#

Finite State Machine

jaunty creek
#

Ahh

sage radish
mortal gust
dusty wigeon
#

Neural Network is way to much unpredictable and inefficient to be use as a reliable AI.

jaunty creek
#

Thank you both for sharing your knowledge ☺️

dusty wigeon
#

What is more, is that lots of approach are made to "win" which is not what you want in a video game setup.

mortal gust
#

I think it all depends on how complex your AI will be. If there are a multitude of combination of actions you might want to look into utility and goal based AI as well.

jaunty creek
#

Good points

#

Thanks again

molten salmon
#

What's the best way of doing 2D pathfinding nowadays? Haven't dabbled with this in years... 🤔 Search results are very.. inconclusive.

bleak citrus
#

I'd start with the AI Navigation package

#

if NavMeshAgents wind up not fitting your use-case, then you can look into something weirder, I guess

lavish sail
#

A-star pathfinding?

#

there's different pathfinding algorithms, depends on your needs

regal olive
hearty jewel
#

Hi. I have a project and recently switched to using dlls I created from my scripts. My problem now is I have missing components everywhere after I deleted all my scripts and just rely on just the dlls. Is there a way to fix this or do I have to re-add all the scripts to my prefabs and objects all over again? (I would assume this is because the metas are pointing to the scripts which are missing).

sage radish
rough sky
#

Is there any way to change a component to an inherited version of itself? I had a bug script, and I want to retain the inspector properties, of which there are many, when changing it to an altered, inherited version. Previously, you could change the Script field in debug mode, but they seem to have blocked that off (asking again, because I didn't get an answer in another channel and I would really like to get the bottom of it)

#

Shown here:

#

Unity 2022.2.11

hearty jewel
#

Might be able to add the script and just copy the values from the older one.

rough sky
#

First thing I tried

#

Paste Component Values is disabled

sage radish
rough sky
#

Yes it does

#

I thought it might be prefabs it was disabled on, but non-prefabs too

tropic vigil
#

Perhaps you could somehow automatize it with a script that searches the GUID references and replaces them for you.

rough sky
#

Would that change all references or just the component on the desired object?

tropic vigil
rough sky
#

I'll try making a tool

#

Thank you very much for helping

lament salmon
scenic forge
#

So yes, whenever you want to use POCO rather than scriptable objects, there's a good chance records is a good fit.

bleak citrus
#

i need to check out records

elder pagoda
#
public class BaseClass<T> 
{ 
}

public class SubClass<T> : BaseClass<T> 
{ 
}

public class Test<T> {

    BaseClass<T> baseobj = new BaseClass<T>();

    void Test() {
        
        FieldInfo fieldInfo = this.GetType().GetFields()[0];

        // how to create new instance of SubClass<T> using fieldInfo here?
    }
}
#

can someone help me? NCD_sadcat

dapper cave
#

this guy uses OnDrrawGizmos to update procedural geometry as you change the value in the inspector. the system uses jobs. it works in play mode but breaks all the time in non-play mode . what's the proper way to do that sort of stuff?

plucky laurel
#

actually ignore you already should have the type in the field info

#

just pass it to activator

#

no im wrong you still need to construct generic type

#

since its T, you need to provide concrete generic arg

versed tundra
#

I'm trying to create a multiplayer game with a Peer-2-Peer connection using a host and clients:

Connecting the players is done using unitys lobby service
And then for actually sending the packets I'm using the relay service

But I want to do make a responsive gun (with actual bullets), ofcourse using the relay makes for a delay of 0.25s, which is way to much

So I'm trying to figure out a solution, the things I've got going are:

  • UDP Hole Punching
  • Spawning the bullets on the clients
  • Client-side predictions

But I've encountered a few problems:

For: Spawning the bullets on the clients
I believe unity netcode for gameobjects doesn't allow clients to spawn gameobjects?

For: UDP Hole Punching
I've found a way to create a hole and connect a client to the host
But how can I let the host reply using the hole (that the client made)
This drawing explains my problem (see below)
(In purple) Unity uses the ip-address send with the package (I think) and replies using this
While I want to use the (in red) ip-address which has a passthrough

For: Client-side prediction
I think it will get really messy and feel "laggy" in a different way
As the idea of the game is to have lots of all different kinds of physics-based bullets
Trying to predict them client-side will be wrong a lot of the time
So the server will have to correct the client way to much

bleak citrus
#

i feel like these are two completely unrelated problems

#

direct peer-to-peer will not ensure that your latency is below a threshold

#

it might reduce the latency, sure, but you are absolutely going to have to deal with it no matter what

versed tundra
#

Hmm is it, because atm the latency is 0.25s and normally with a direct connection in games you can expect a latency of 0.05s?

#

So wouldn't the bullets seam more fluid then?

scenic forge
#

I mean, light only travels so fast.

versed tundra
#

Yeah but still 0.25s really is a lot compared to other games
How do other physics-based multiplayer shooters work then?

#

the explanation I can think of is that they use a direct connection between the client and server
and that they use either client-side prediction or let the clients handle their own bullets

scenic forge
#

250 ms is pretty high tbh, but 50 ms is also not really a realistic expectation unless the physical distance is really just that small.

#

Riot Games built their own internet cables across the entire US and set up their servers in the middle of the continent, and most players still get 60+ ms ping.

versed tundra
#

Yeah that's fair enough

#

But how could I solve my problem then?

bleak citrus
#

it gets hairy

undone coral
#

what is your goal?

#

to make a multiplayer FPS?

#

and if so, is there a specific gameplay innovation you have in mind?

versed tundra
#

Wave your noodle arms around to assert dominance!Experience hype-filled dueling! Shoot, block, and jump your way to victory with your shotgun-rocket-launcher-that-shoots-heat-seeking-bouncy-missiles or one of the other over 11.2 million different powerup combinations.Features65+ Unique powerups70+ MapsAAA Face CustomizerOnline MultiplayerLocal M...

Price

$5.99

Recommendations

14034

▶ Play video
#

Take this game

#

but in 3D

#

that gets the gist of it

errant plinth
undone coral
#

what do you want the game to look like

versed tundra
#

I have no idea XD

#

I'm just prototyping atm

#

trying to see of it's actually fun to play before comitting

undone coral
#

hmm

undone coral
bleak citrus
#

i would suggest writing a throwaway game or two first

#

architecting multiplayer correctly is...an experience

undone coral
#

there isn't that much to it. on a LAN, latency is so much lower than rendering time, you can implement a lot of things naively and things will just work.

#

it really depends what you want to do

#

and what you want to learn

versed tundra
#

I've made a game 4 years ago in multiplayer

#

and about 6 months ago I made an entire server-client library for C#

#

which really did refresh everything

#

and I've made a simple 2d multiplayer platformer like a year ago

versed tundra
undone coral
#

like you haven't said a specific 1 piece of innovative fps gameplay yet

#

so if you're into Engineering and not really Game Design

#

if you don't already know what it is that you want to do that is original, don't make it in unity

#

there are basically no networked multiplayer FPS games that do all the innovative stuff in ROUNDS (you tell me what it is)

#

Paint the Town Red is a chaotic first person melee combat game set in different locations and time periods and featuring a massive Rogue-Lite adventure. The voxel-based enemies can be punched, bashed, kicked, stabbed and sliced completely dynamically using almost anything that isn't nailed down.In the Scenario levels you'll need to use your wits...

Price

$19.99

Recommendations

20038

▶ Play video

Revival Productions is proud to present the ultimate 6-degree-of-freedom shooter, OVERLOAD, from the creators of the classic game Descent. Overload combines intense action with awesome graphics and effects to create the ultimate zero-gravity shooter. Overload features an engaging single-player story campaign, intense survival mode, online multi...

Price

$29.99

Recommendations

1353

Metacritic

74

▶ Play video
#

Plan the perfect heist using creative problem solving, brute force, and everything around you. Teardown features a fully destructible and truly interactive environment where player freedom and emergent gameplay are the driving mechanics.Tear down walls with explosives or vehicles to create shortcuts no one thought was possible. Stack objects, bu...

Price

$29.99

Recommendations

63933

Metacritic

80

▶ Play video

ULTRAKILL is a fast-paced ultraviolent old school FPS that fuses together classic shooters like Quake, modern shooters like Doom (2016) and character action games like Devil May Cry.Mankind has gone extinct and the only beings left on earth are machines fueled by blood.But now that blood is starting to run out on the surface...Machines are racin...

Price

$24.99

Recommendations

52223

▶ Play video
bleak citrus
#

you do not need some mindblowing new idea

#

you need a fun game

#

note that a mindblowing new idea can help with that, for sure (:

#

multiplayer is challenging because it demands that many people play the game, or else it becomes valueless

versed tundra
#

I get all your points

#

but there's one important thing you don't know

#

The game is just so I can play it with my friends

#

if I'd turn out to be something really fun, then sure I'd try selling it

#

but otherwise, just making it to play with my friends and to put it on my portfolio is good enough

undone coral
#

you will probably want to start with e.g. hammer editor for Source 2

#

unity isn't really suitable for making networked multiplayer FPSes with immersive physics

#

you'd be writing a new game engine from scratch

#

you should also check out the new unreal editor for fortnite editor

#

which is like state of the art for community authored FPS experiences

#

i understand it looks like unity has something to offer here but it does not

#

@versed tundra because making (1) a robust multiplayer FPS engine that also has (2) naturalistic physics and (3) has support for expressing gameplay in terms of naturalistic physics costs $10-100m to make

#

and unity doesn't make that any easier

#

does that make sense?

#

unity doesn't have anything valuable that would help you achieve that goal. the least challenging part of all this is the networking

#

but Overwatch is essentially the first FPS engine that meets all the reqs there, despite networked FPS existing for decades

bleak citrus
#

...what?

#

you don't have to make an ultra high-powered super-elaborate multiplayer engine that can do everything

#

multiplayer physics is certainly harder, but it's not wildly unattainable

#

and I certainly believe it would be a serious challenge

uneven portal
#

i made a multiplayer game last months

#

its about apples

#

my friend coder always forgets to add upper and lower arms

#

his caoding is so sloppy he cant even reroute a data tgread

undone coral
#

oh i can express my game rules using naturalistic physics

uneven portal
#

Computer Programming in 4 Steps
Step 1: Identify the problem. ...
Step 2: Find a solution. ...
Step 3: Code it. ...
Step 4: Test it.

undone coral
#

using OnTriggerEnter or whatever

#

and rigidbodies

#

and you can model all this gameplay using naturalistic physics

uneven portal
bleak citrus
#

then we discover that trigonometry is super inconsistent between different platforms

#

splat

abstract hill
#

Hi everyone, I was wondering if someone could decipher what was meant by a solution to a problem I'm having with Preview Render Utilities and using interactive Handles. I brought this up in the editor chat a few days ago but I don't think anyone really understood what I meant there.

My problem is that I can't seem to get handles working interactively within a scriptable object. The only person online who seems to have solved this is from this thread on the unity forums. https://forum.unity.com/threads/previewrenderutility-and-handles.859168/#post-5710978 however I don't understand what they mean when they say offset from bottom left corner of window to bottom left corner of preview area must be added to Event.current.mousePosition. Also pixelRect and aspect of camera in PreviewRenderUtility must be updated to size of preview area in Layout pass

Does anyone know of any example code to show this working, I assume i'd need to do something like process the inputs manually myself if I would need to add offsets to the mouses position but I also can't seem to find any examples of where that is actually being done. Any help on this would be appreciated. (Same goes for if handles are not the best idea, and if there is a different tool to use other then them for the preview Render utility).

undone coral
#

but you cannot simultaneously (1) support the whole design space of naturalistic physics expressed gameplay, which is exactly what @versed tundra was showing me in ROUNDS (2) be networked

uneven portal
undone coral
#

@bleak citrus does that make sense

halcyon hare
undone coral
#

that is fine to use

bleak citrus
uneven portal
halcyon hare
#

?

undone coral
#

like if you have no idea what you want to make

#

okay, you are not going to succeed in making any networked gameplay period

uneven portal
undone coral
#

because you won't know how to "fake it"

#

you don't even know what "it" is

#

if you don't want to have any shackles - that is the equivalent of "i want to express my gameplay in naturalistic physics"

#

well unity doesn't support that in a networked environmen, and there is no pre-existing code that makes achieving that easier

#

that is my point

bleak citrus
#

i don't think "i don't have a strong idea of the core gameplay loop" is the same as "I want to be able to do anything"

uneven portal
undone coral
#

whereas Overwatch's editor does let you express a lot of gameplay naturalistically

undone coral
#

it's the grappling hook meme

bleak citrus
#

true

uneven portal
#

@pale ocean What a flippin spatula

undone coral
#

i personally do not find naturalistic and immersive physics gameplay very interesting

#

especially not in a first person perspective. i feel like every parkour idea has been done to death

#

if you want to do that ON TOP OF "it's spells"

#

that's what overwatch is. $100m engine

#

go for it. use their completely free game and editor

#

indeed, the #1 custom arcade game in overwatch is literally parkour

#

if you really need to use custom assets freely, yes you'll have to use source 2

#

just like respawn did. you will need $1m instead of $100m

#

titanfall 2 has a lot of "naturalistic physics gameplay with spells"

#

@versed tundra does this make sense

uneven portal
#

in titanfall 2 deshawns coding of the poly glippiks were unmatched and unrivalled in this generation thus far

elfin tundra
#

is there a way to make a function run when a certain complex condition is satisfied? currently, i do all my checks in the update function every frame, but i have multiple conditions one after another and now my update function is getting cluttered and i'd like to consolidate these conditions and response functions in a different place. also, it is kind of slow and unnecessary to be doing all the checks every frame.

#

something like event handling i suppose

uneven portal
#

Yes just put some frayed chuckin in the vents

versed tundra
versed tundra
versed tundra
#

so since I want to try out my game idea

#

to see if it's fun to play

#

and to goof around with my friends

#

I think it's a great candidate

#

The time I'd have to put into learning unreal, learning the basics again like player movement and such and beginning with smaller projects again... I'd be so much more than trying to make it work with unity i think

#

And well yes ofcourse I'd have learned a new skill (being unreal engine)... I don't have and want to put in all that time rn

#

and I think I can make it with unity in that time

#

that's why I've chosen Unity for this project

#

Does that make sense? @undone coral

versed tundra
#

But as for my problem it self

#

it looks like the bullet thing is the hardest part

#

the player movement is synced great

#

the collision detection is aswell

#

the bullet movement aswell

#

just the spawning of the bullets isn't

#

and as for the rest of the game

#

picking a card isn't something that a little latency could hurt

#

and as for my prototype, that will be it

versed tundra
#

I planned out the entire prototype

#

I've made requirements, sketched out scenarios, ...

#

I planned it all out

#

Just the simplest way of explaining my game to you was with the rounds but in 3D example

#

I have no idea where the game should turn to once the prototype has been made

#

or what I want to do next

#

but as for what I want to make rn, I have a clear description

versed tundra
undone coral
#

okay well

undone coral
undone coral
#

before you discover how little actually works

#

so it really does matter what the specific mechanics are

#

because that will tell you whether you need the flexibility of naturalistic physics or not

versed tundra
undone coral
#

i am trying to help you thrive

#

someone who jumped right into overwatch arcade editor would already be able to try the original mechanics

versed tundra
versed tundra
#

the question was all about 2 things entirely in isolation
How they work with the game is all planed out already

undone coral
#

you gotta name a specific mechanic for this to be helpful

#

if it is beyond the pre-existing traditions of FPS engineering then you are essentially saying "i want naturalistic networked physics"

#

why not say what it is

versed tundra
#
  • Can I fix UDP hole punching so I have less latency
  • Can I spawn an bullet on the client, or should I really bother with client-side predictions for it
undone coral
#

it's not sensitive

versed tundra
#

I litteraly already said what it is

undone coral
#

like, a grappling hook?

versed tundra
#

it isn't anything out of the ordinary

#

just spawning a bullet and making it move using the unity physics engine

undone coral
undone coral
versed tundra
#

unity physics doesn't even have to do with the problem

undone coral
#

hmm

versed tundra
#

it's just the bullet spawning

#

the physics of the bullet already works

#

it's already synced

#

I've tested it

#

ofcourse, fixing the spawning with client-side prediction would mean that I'd have to predict the physics...
But that's entirely doable

#

that's part of my question tho.. should I try to do that, or can I spawn it in another way

undone coral
# versed tundra - Can I fix UDP hole punching so I have less latency - Can I spawn an bullet on ...
  • Can I fix UDP hole punching so I have less latency
    in the current tradition of fps engineering, servers are hosted in datacenters. so there is no p2p approach practiced anymore, since for the average user it doesn't work well.
  • Can I spawn an bullet on the client, or should I really bother with client-side predictions for it
    in the current tradition of fps engineering, everything the player does is instantaneously simulated on the client. a special kind of physics, that aren't really naturalistic so i wouldn't call it physics in the same sense of Unity Physics, is used to robustly reconcile conflicts between the views of the world between various clients.
#

i mean do whatever you want

#

i don't know why you are dealing with unity physics

#

if you don't need naturalistic physics. according to the example you showed me, you do

#

this isn't a debate

undone coral
#

it's not saying much that 99% of people will fail at doing this. but here i am trying to help you and you are thoroughly avoiding the patterns of the 1% who do.

versed tundra
#

Exactly, so I'm asking here if anyone does know how to do it for another game (not an fps).. That way maybe I can figure it out

#

not everything you make has to be made before yk

#

That's an answer to a question

#

thx

versed tundra
#

I haven't said anything new

#

the example I showed you as rounds but in 3D isn't something groundbreakingly new

#

just you jumping to conclusions

versed tundra
#

I'm looking for help to my specific question I asked

versed tundra
undone coral
#

isn't that what we've been talking about?

versed tundra
#

And can someone help me with achieving udp hole punching in unity

versed tundra
#

Just as an example

undone coral
#

and that's meaningless

#

the right way to do this is to host the server in a datacenter

versed tundra
#

There is no right way to do it.. The way I've chosen is p2p and udp hole punching is a communly used way of achieving that

undone coral
#

you can use amazon global accelerator, which is like riot's private networking as a service

#

well what i'm trying to say is that implementing p2p is just turning everyone's home network into a datacenter

#

it is at least as complex in terms of what you'd have to achieve with the networking

versed tundra
#

I know what p2p is

undone coral
#

you're welcome to check out amazon global accelerator or azure's network traversal service

versed tundra
undone coral
#

"UDP hole punching" is one strategy of many. the webrtc (and ortc / webrtc 2.0) standard has explored this problem space

#

steam networking is essentially ICE 0.9

#

steam also provides TURN servers, which is like a relay that follows a standard protocol

versed tundra
#

Exaclty

#

So how could I implement that myself

undone coral
#

with $1m ?

versed tundra
#

The relay is done with unity services

undone coral
#

that's what i'm trying to say

#

unity services is vaporware

#

i've been trying to tell you this many times. unity doesn't have stuff for this

versed tundra
#

And how do I implenet ICE or STUN or UDP hole punching

undone coral
#

it looks like it does

versed tundra
#

Idc what you think about there services or their implementation

undone coral
versed tundra
undone coral
#

of course. if you have at least a million dollars

#

it's not like i'm just spewing a bunch of warble garble to scare you off

#

it's just i don't see what this has to do with making a game

#

seems like a huge distraction and you will be destined to give up on this

#

because it's pointless and uninteresting. use steam networking or a hosted service

#

unity services relay isn't the same as steam networking

versed tundra
#

There you go assuming something again

undone coral
#

i believe it is either azure's network traversal service or aws global accelerator repackaged. if even. it is probably "coturn in many places."

#

alright well i'm sorry i can't be more help

versed tundra
#

I want to try and do UDP hole punching or an alternative

#

It's okay if you find it uninteresting

bleak citrus
#

do you have a game yet? if not, there's no real point in implementing very specific networking technologies

versed tundra
#

But I do

undone coral
#

you didn't answer my 1 question so

#

that's how i could be more helpful

mortal gust
mortal gust
#

Better go with relay options, which is free if you deploy your game to steam last time I checked.

undone coral
#

and if your jonathan blow sometimes it works out

#

and if you're not it doesn't

#

like you can have $1m or 10 years. pick your poison

#

if i were the user, i would make my FPS in overwatch arcade

versed tundra
undone coral
#

if you ask people who come from industry the same question, they say the same thing to people who have no track record

#

it's not meant with any offense

#

it's just to say, with a budget of 0 and no evidence you can finish something you've been working on for 10 years, it's reasonable to advocate for a better solution

#

but dicking around with internet networking... like 0 people will be able to play the game until a year of product development is done

versed tundra
#

I'm interested trying to learn the thing I asked

#

Even of theres no succes with it

#

That's okay

bleak citrus
#

just be careful to not XY-problem yourself

versed tundra
#

I have the majority of the game finished and for the prototypes sake.. It's okay if theres latency if it will be fixed when I switch to a paid service

#

I Just want to learn about the topic I asked, and it would also fit in nicely into my prototype

versed tundra
bleak citrus
#

you want to do X

#

you think you can achieve X if you can just do Y

#

now you are trying to do Y

undone coral
#

now multiple people are giving you feedback that you have to improve your communication skills if you want to achieve your goals.

#

you could maybe download a unity asset that does "udp holepunching"

#

and if you want to learn how it works, study that asset

dusty wigeon
#

https://unity.com/how-to/manage-network-latency

There's multiple reasons for not having server authoritative gameplay code run both client side (with prediction) and server side. But how do you make sure the throw feels responsive and that your client doesn't have to wait for a full RTT before seeing anything react to their input?

A trick often used for lag hiding is to trigger a non gameplay impacting animation, sound, or VFX on player input immediately, but still wait for the server authoritative gameplay elements to drive the rest of the action.

If the server has a different state, the worst that happens client side is that you've played a quick but useless animation. It's easy to just let the animation finish or cancel it. This is referenced as action casting or action anticipation.

versed tundra
#

Does that make sense?

mortal gust
undone coral
#

you can't use its physics. there isn't even a 1.0 version of DOTS yet

#

it's just a bad engine for this

versed tundra
#

I know that it's a bad engine for this.. But it's good enough to make a quick prototype

#

It will be with its flaws

#

But it's faster then learning a new game engine

dusty wigeon
#

What are you talking about ? Tarkov is made with Unity.

versed tundra
#

Which I don't have the time for rn

dusty wigeon
#

I would consider Tarkov to be enough well put game.

undone coral
#

i'm saying that it provides the lowest ROI of the commercially available options to do so

#

even then, Tarkov is phenomenally buggy

dusty wigeon
#

Like every other game.

undone coral
#

no. overwatch has almost zero bugs

#

this is absolute crazy sauce

versed tundra
undone coral
#

i think you know that there is a world of difference in terms of robustness between the two unity FPSes with audiences* and the big commercial FPS game engines

dusty wigeon
#

We didnt play the same game

undone coral
#

you are going to hurt your credibility here

dusty wigeon
#

I remember Reaper being able to break the game with his TP.

#

Every where.

undone coral
#

i could go and ask the tarkov devs for their opinion

#

would that settle the matter?

#

of course they would agree, overwatch - which was developed with 100x the budget that they had and 10x the experience - is an order of magnitude more robust

#

it is negative ROI to try to make a unity FPS

#

i don't think anyone should

#

not yet at least

#

even if you had $1m i wouldn't do it

#

maybe if you had $10m and DOTS hits 1.0, then it's worth trying. but to what end? to support the switch?

#

you might as well use Unreal. $10m will go a long way with Unreal

dusty wigeon
#

There is nothing to be settle here. There is a large amount of game that achieved decent result with Unity. Our Friend does not aim for the best game ever, he only wants to make a little project on the side for his friend.

versed tundra
#

Exactly

undone coral
#

it is beyond the budget and abilities of the user to make a working networked FPS in unity

#

you can use UFPS for prototypes, but why? why not use overwatch arcade at that point

#

i've been asking what the goal was

#

and the user basically said "learning how to create the Amazon Global Accelerator product"

#

which is not a unity problem

#

or twilio network traversal service

#

and i answered it. you run coturn in a bunch of datacenters

#

that is what twilio's network traversal service is

#

you can use amazon global accelerator to do anycast IP routing, or you can use DNS to load balance.

#

that's it. that's the whole product.

versed tundra
#

There you go making actual questions into things that I didn't ask

dusty wigeon
#

@versed tundra , you can create your own relay. It could help with latency if you and your friend all lives near each other.

versed tundra
#

I'd be a great temporary solution.. Especially since everyone lives close by and it's just to test out the idea

undone coral
dusty wigeon
#

That is what we did at our company. The relay was not reliable enough.

undone coral
#
  • anycast ip or dns "srv"
versed tundra
undone coral
#

azure network traversal is so cheap there's no point

#

yuou don't even have to use STUN/ICE/TURN to use it

versed tundra
#

Seriously @dusty wigeon has given me better advice in that one message then your e ntire essay

dusty wigeon
#

Also, you must note that UDP hole punching does not work with every NAT. If I remember correctly.

undone coral
versed tundra
#

Okay

#

Good for you ig

versed tundra
#

I accepted to fact that some people would have to play with 250ms delay then

regal olive
#

lol this doctor guy is a joy to read

compact ingot
#

just dispensing bitter medicine

plush hare
#

@versed tundraThere's nothing difficult about p2p via udp hole punching

#

This entire argument could've been avoided with one google search

plush hare
plush hare
# undone coral but you cannot simultaneously (1) support the whole design space of naturalistic...

I'm not sure what you're talking about when you keep referencing "naturalistic physics". I assume you're just talking about a standard 3d physics engine.
There isn't anything stopping you from predicting and rolling back physx objects in a networked unity environment.
Of course physx isn't designed for this, so you might notice some small pops and teleportations especially since most network engines only sync data with limited precision, but it's definitely possible and works fine for the average joe.

plush hare
plush hare
# versed tundra There is no right way to do it.. The way I've chosen is p2p and udp hole punchin...

There is a right way to do it, but it depends on your game.

Small zombie survival game where 4 friends can play together? P2P is fine.

Competitive game where randoms are versing each other? You must have dedicated servers. If you don't: a.) the host can and will cheat & b.) people will get ddosd to the point where nobody will play your game anymore. Relays solve the ddos part, but will not solve the host cheating part. If you're going to be spending that much on bandwidth, you might as well just rent the raw servers.

#

Take GTA V online for example. It's basically P2P.
Modder doesn't like that you killed him? Oh well, you're getting blown up repeatedly now / booted from the lobby / put in an unplayable state / ddosd.

plush hare
stark acorn
stark acorn
#

but you know, that's what they all say, i'm sure somewhere is wrong i know

#

i just couldn't track it

regal olive
#

Thank you to everyone who helped or offered solutions for my edge grabbing problem! I have it about 90% working. I can jump at an edge with about 99.9% success rate and consistency, with fully-working edge getup options. But falling down onto one generates different results.

main pawn
versed tundra
#

So it's fine if the host can cheat

versed tundra
versed tundra
plush hare
#

@versed tundraYou said that latency was affecting your users. 250ms

versed tundra
plush hare
#

Implementing it in unity is 0 different than implementing it in regular c#

versed tundra
#

But I have to said the ip for the unity netcode transport

plush hare
#

You're telling me unity doesn't support p2p?

versed tundra
#

No I'm asking how I can change the ip where the host sends the packet towards

#

Like the drawing I made in the original post

plush hare
#

@versed tundraIsn't that the point of using a transport framework?

#

To send data to clients?

#

I don't understand what you're struggling on

versed tundra
#

So if I use UDP hole punching, (in simple terms) an external ip is made for a specific machine... If I do that for the host, I can setup the ip-adress in every client to that external ip (no problem)..

But don't I have to make the host go through a 'hole' instead of the default ip if it wants to talk to a client.. If so, how do I change that ip in unity?

plush hare
#

Again, all of this is publicly available on google.

versed tundra
plush hare
#

I mean, yeah

#

you'll probably be talking to multiple IP addresses at once

#

If you're asking me how to do that inside unity's transport framework, I have no idea.

#

I've never met anyone who uses that.

versed tundra
#

No I mean:
You have the public ip with a port that has been punched.. So now their is an entry in the NAT which you can use

But your router changes the external ip-adress depending on which port in the NAT you are using (?)

So how can I let the host talk to the changed ip-adress instead of the standard ip for the router

plush hare
#

My public facing IP address has not changed in over a decade. If your ISP DOES change the IP address, It's probably going to be once a week.

#

Not while you're in the middle of doing things

versed tundra
#

How does a router know where to route the incoming data to then?

Something has to be different when sending a packet to specify a location in the NAT

What chances then?

plush hare
#

Again, you need to look at how UDP holepunching works

#

I can guarantee that residential routers are not changing IP addresses in the random middle of the day

#

If you had bothered googling it, you would also find out that Unity's Netcode for GameObjects has built-in P2P support.

versed tundra
#

I did Google about it...

versed tundra
#

Or do you mean the lobby en relay system they provide?

plush hare
#

that's the premise of UDP holepunching.

versed tundra
#

Yes I understand that.. But as I said before, how does the router know which entry to choose from the NAT when receiving data...

Something has to say that in the packet right? So what is that something?

plush hare
#

Modem sees incoming packet. Has any computer on my network talked to this IP address recently? No? Drop.

#

It's no different from manually opening ports on your network. When you manually open a port, you have to specify the local IP address on your network for your router to forward the packets to

#

in this case, the router handles it for you.

#

I think I know what you're getting confused on, and I'm going to do my best to explain it

#

Are you confused how the packet gets back to the physical computer behind the shared IP address?

versed tundra
#

Oh I thought the router asked:
Has any computer on my network talked through this port? No? Drop.

plush hare
#

port yeah

#

sorry

#

I'm stoned rn

#

It probably looks at the IP address too. I don't work on routers

plush hare
#

So each computer on your network has a port. This is a value that can go from 0-65565

#

Whenever you start a networked application, it chooses a port in that range

#

When you send data to the server, it sees your router IP address and local port

#

So then when the server sends data back to the client, the port tells the router which computer it's going to

#

That way you can have many users behind a single public IP address talking to the same server

#

it sees each computer individually

versed tundra
#

Okay but how does that play out when using udp hole punching?

plush hare
#

Let's say the server and client both know each other's IP addresses

#

if the server randomly during the day sends a packet to client,

#

the client's firewall in the modem is going to drop it

#

because the client hasn't talked to that server any time recently. So it has no business talking to our home computers

#

With UDP hole punching, the client talks to the server first

#

then the NAT table gets updated

#

"server" in this case is another client behind a NAT btw in case I'm confusing you

#

They'll both need to talk to each other

#

until the NAT tables are updated properly

#

which is usually just the first packet

versed tundra
plush hare
#

Correct

#

actually

#

no

#

When you're talking to the connector server, you'll need to be on a socket connection

#

then your game server connection will be a separate socket connection

#

I'm high rn so my brain is functioning at like 5% but this should all make sense logically to a sober person

versed tundra
#

What's a socket connection?

plush hare
#

It's what a UDP or TCP thing sits on

versed tundra
#

Aha

versed tundra
plush hare
#

None of this applies for a real dedicated server setup

#

only residential to residential connection

#

the old call of duties used to do it this way. P2P

#

I'm going to try to write this out step by step.

  • Server is a home PC
  • Client is also a home PC. Both are behind NATs.
  • 3rd party server is a server in a datacenter

Client wants to connect to server. He tells the 3rd party that. 3rd party server tells client the server IP address and port, and tells the server the client's IP and port.
They can both send a specific packet every 1 second. If the packet goes through, then you can probably assume the P2P connection has been made.

#

In this case, the client will also have to tell the 3rd party server the game port open for the client's socket connection

#

Since remember, the client socket sending data to the server is going to have a different network port than the game socket port it's listening on

#

Questions?

versed tundra
#

So I'd have to look for the open port first?

plush hare
#

You can get the computer to search for you

#

and automatically do that

#

But you do have to manually send it to the server

#

Why don't we use the same socket? Web requests use TCP. High frequency game updates use UDP.

versed tundra
#

Yeah that I understand

#

But then I'm right that the server has to respond to the opened port of the client.. Instead of the default port of the game?

plush hare
#

Correct. The "default port of the game" is what the clients connect to

#

In this sense, P2P, you wouldn't really have a default port

#

I mean you could. But generally you want someone's home computer to choose for you

#

in case it's already in use.

#

Dedicated servers in a datacenter usually come with dedicated IP address for that server only. Which means the entire port range is free for you to use.

versed tundra
#

Yes.. But how does to server respond to the client who punched out a port?

whole saddle
#

I downloaded unity!!

plush hare
#

There must always exist a 3rd server in p2p

versed tundra
#

Does it have to look for the port aswell?

versed tundra
plush hare
#

Your dedicated server will have it's own default port. This never needs to change

#

otherwise all of the home computers wouldn't know where to initially connect

versed tundra
#

Yes I have it that far

plush hare
#

You're set, then

versed tundra
#

But I'm just using the dedicated server to initialize the connection between the host and client right?

plush hare
#

Correct

#

You're just telling each other their IP addresses

#

and ports

versed tundra
#

Exactly

#

So what I'm coming towards.. The port of the clients isn't a default one?

plush hare
#

always computer generated

#

on home computers

#

even if the home computer is acting like the host

versed tundra
#

So how do I tell the host to which port it has to send the message using unity?

plush hare
#

No clue, never used Netcode for gameobjects

#

you're on your own for that

versed tundra
#

So yeah that was my entire question

plush hare
#

@versed tundrahttps://unity.com/products/netcode#:~:text=Does%20Unity%20Engine%20work%20for,other%20clients%20connect%20to%20it.

Unity

Explore Unity’s new first-party multiplayer networking solutions, a.k.a Netcode, to create your multiplayer games.

whole saddle
#

Hi hi hi

plush hare
#

Scroll down to the bottom

#

"Does Unity Engine Work For P2P?"

#

That's as far as I can help with that

versed tundra
#

Yeah I've read that.. But it doenst help with my problem

plush hare
#

You can always use C# sockets

#

for the initial connection

versed tundra
#

That's the only thing I can find on anything udp hole punching related

plush hare
#

@versed tundraUse a C# socket to initialize the connection

#

after that, start the game normally through NGO

#

or something

versed tundra
#

I've done it before

plush hare
#

Is your game only through steam?

versed tundra
versed tundra
plush hare
#

I mean, you could probably choose a widely unused port

#

and just use that

#

for the host

#

65565 is a lot of values

versed tundra
#

So just try a widely unused port and if udp puncture fails on that specific port.. Fallback to relay?

plush hare
#

whatever works for you

versed tundra
#

No but is that what you're saying?

plush hare
#

I'm thinking hang on

#

I would personally have the computer choose the ports for everything

#

if it was my project

#

I don't know the capabilities of NGO

versed tundra
#

Yeah I want to know if/how that can be done with NGO from host to client

#

Client to host is no problem

plush hare
#

How do you start the server

#

like send that line of code

versed tundra
#
        Allocation allocation = await AllocateRelay(maxPlayers); 
         string relayJoinCode = await GetRelayJoinCode(allocation); 
  
         await LobbyService.Instance.UpdateLobbyAsync(joinedLobby.Id, new UpdateLobbyOptions 
         { 
             Data = new Dictionary<string, DataObject> 
             { 
                 { KEY_RELAY_JOIN_CODE, new DataObject(DataObject.VisibilityOptions.Member, relayJoinCode) } 
             } 
         }); 
  
         NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(new RelayServerData(allocation, "dtls")); 
  
         NetworkManager.Singleton.StartHost();
plush hare
#

Ok

#

So then StartHost should probably automatically assign a port

#

NetworkManager.singleton.networkPort

#

Which can be found here.

#

You don't need to send the dedicated server your IP address since it already can see it.

versed tundra
plush hare
#

no clue

#

that's all the help I can give on this topic

#

you'll be able to figure it out

versed tundra
#

Okay thx

errant plinth
#

Carrier grade NATs shakes fist

#

Went with Steam's Datagram Relay for my game which is an FPS shooter. It works quite well

#

Downside is the tie-in to the Steamworks platform

#

I've heard that Titanfall 2 uses Playfab so it might be interesting to check out that out

regal olive
#

Any solution for this crash SIGSEGV?

thin mesa
mortal gust
# main pawn can you elaborate please, it would help me alot

What part do you want me to elaborate on? In the RaycastInput input variable you're setting End to be a scalar of 20f instead of a point in space float3. Then if you don't have any plane/background that this initial ray will hit, your method might not do the overlapSphere and find entities when it should.

hollow lintel
#

does anyone know why im getting an android project instead an apk when i build?

#

export project is not ticked

untold moth
#

Are you clicking "Build"/"Build and run"?

dark oar
#

does Semaphore.WaitForSignal cause performance issues? It takes up about 80-90% in logcat

hollow lintel
#

here is the code im using

#

i tried this in editor it works fine

untold moth
#

Not sure then, but chances are you're missing something 🤷‍♂️

hollow lintel
#

emmm

untold moth
hollow lintel
# untold moth It does?

yea it outputs apk but when i use command line to build android it just resolve to an android project

#

just this line

#

where JenkinsPipeline.BuildAndroid calls Buildproject

#

it just handles commandline inputs

#

you get normal apk from editor, calling this method

#

you get this from commandline

#

so weird

dusty wigeon
#

It seems to me that it is unable to package your build correctly. It could be cause because Unity is unable to find the Packaging Program. Try to manually package the resulting build. (It can probably be done from Android Studio)

devout coyote
#

Opinions on using FindObjectOfType vs a more traditional SomethingManager.Instance? I've noticed that in my team we use a combination, and I'd like refactor such that we use one of the two, functionally they feel very similar, the .Instance method just feels like more upkeep though, and there's probably some performance overhead if you were to use FindObjectOfType on every frame, but it's really just assigned in either Awake() or Start()

bleak citrus
#

I usually go with the singleton pattern

#
public class GameController : MonoBehaviour
{
    private static GameController _instance;
    public static GameController Instance
    {
        get
        {
            if (_instance == null)
                _instance = FindObjectOfType<GameController>();

            return _instance;
        }
    }
#

(that gets configured on the first attempted access)

#

This makes it simpler if you have several things that all want to talk to each other during setup

devout coyote
#

Look at that boilerplate though :s

bleak citrus
#

it's like eight lines

devout coyote
#

This is better than the singleton implementations we were using though, they were something like this:

public class GameController : MonoBehaviour
{
    public static GameController Instance { get; private set; }
    
    private void Awake()
    {
        Instance = this;
    }
}
#

But now that I look at it

#

Leads to some nasty race conditions

bleak citrus
#

I cribbed this one from someone on the unity forums

#

yeah, that's the downside

#

I used to do that.

bleak citrus
devout coyote
#

They don't? I was literally just going to try that x)

dusty wigeon
#

Just use an Abstract class...

public abstract class Manager<T> : ManagerBase where T : Manager<T>
#
public abstract class ManagerBase : MonoBehaviour
devout coyote
#

Not a huge fan of inheritance either

hollow lintel
devout coyote
#

But might be the best solution here

bleak citrus
#

zzz

dusty wigeon
bleak citrus
#

yeah

devout coyote
#

Aren't there any decorators that could help me here?

dusty wigeon
#

What would you add in functionality ?

devout coyote
#

Attributes in C# mb

#

Haven't really worked with them at all though

dusty wigeon
#

You can create your own for sure.

#

But it won't necessary be better.

#

In fact, you should probably stick to simple pattern if possible.

hollow lintel
#

well if you want a clean way to implement singleton, you can try a IOC container with dependency injection.

devout coyote
#

Just when you think you've escaped containers

#

there they are again

hollow lintel
#

framework like zenject does this tho

bleak citrus
#

i get an allergic reaction when I see "dependency injection"

#

since i usually get shown an example that takes 500 lines of code to add two numbers

devout coyote
#

Just don't really feel like setting it up tbh

#

Once you get some external services added in though you kind of have to

hollow lintel
#

yea setup work is cumbersome

#

if your project is not that complicated

#

just use Manager.Instance

devout coyote
#

Gonna go with inheritance I guess

bleak citrus
#

in my game, I only have one big-ass singleton for the game

#

it holds references to other important things, like the interface controller

#

I do need to think about this a bit for when I add a menu scene

dusty wigeon
#

That is usually call ServiceLocator

bleak citrus
#

SerivceLocator, big-ass service, potayto potahto

#

(:

devout coyote
#

Already ran into a problem with inheritance, some inherit from MonoBehaviour whereas others have NetworkBehaviour

#

MAN

bleak citrus
#

splat

#

well, you can just do something similar for NetworkBehaviour

dusty wigeon
#

NetworkBehaviour inherit from MonoBehaviour ?

mellow plinth
#

Which processor directive(s) can I use to check if the target platform is AOT compiled?

dusty wigeon
mellow plinth
#

Oh, ok

#

IL2CPP is always AOT and Mono is always JIT? Or can Mono be also AOT?

devout coyote
dusty wigeon
#

I would say so, however I am not 100% sure. There is definitely a correlation there though.

#

That being said, I think Unity does not support the AOT of Mono.