#archived-networking
1 messages ยท Page 110 of 1
It's bold and risky in general
yeah
Not a lot of companies make direct claims about their competitor
tru
Yea they do sometimes, but you might open up yourself up for liability.
And afaik, they don't always do it, most likely because you wanna be damn sure you don't wildly misinterpret anything
Do you have more than 20 friends playing at the same time?
but what do you mean friend set up servers for their friends?
You would have to pay for higher tiers if you want more CCU
yeah
ok
but how many people do you expect playing
oh
ok i see
then you will have to buy higher
There is one networking solution that i started on
it is free
pretty much
other than the one time payment at the end
its steam
but it is really confusing
Please send your messages as one message instead of splitting it into 5 ๐
man that is hard
i talk alot
whats mirrors max connection?
oh
i thought mirror was always just for split screen games
me too
Does anyone know how to stop Photon Animations overriding my transform view?
Yea no ๐ Mirror is a relatively normal networking solution
Are your animations using root motion?
It's a concept in animation where the animation controls the position of the object, which helps with syncing the movement with the animation.
Hmm so is this a good thing
cause there is a checkboxs
in my game
sorry for the lines thing i need to get used to that ๐ฆ
Only you can possibly know if you want root motion enabled or not
Yea they are different approaches
Noticed you said you use FishNet.. Is it actually production ready? I was considering trying it out at some point
Or you know, maybe not full scale production ready, but at least quite viable compared to Mirror?
This seems like a dedicated server <-> client architecture
It's also lower level than using one of these frameworks
Sorry just got into the office. I started FishNet sometime throughout it's beta and a lot of ground has been made. The creator says there is a lot more planned but that it is fully functional and has every feature Mirror does. I do not recall their exact words, something about wanting to add more transports and documentation. I'm seeing they just recently finished their API documentation so I imagine guides are next.
It doesn't have every Mirror feature
Finished or started the API documentation? I thought DocFX was just setup
I have a feeling if you asked the owner they would say no to being production ready, but I suspect that is to cover themselves before they go official. I've however had no problems or limitations using it for awhile now. It really is easy to use and they seem legitimate in their wants to make a good product.
I guess documentation in the code mirrored on a site counts though
Yeah, the latter part of what you mentioned here is definitely why I am interested
very frequent updates and dev seems passionate
It also mentions future plans for many features I have wished for in Mirror, so glad to hear it actually seems to be quite viable
I will be checking it out, thanks!
Thats a good vid by tom
ig
Erick Passos tho said it wasnt the best practises to my knowledge
Yeah
Technically
You still must add filters, organize, and comment everything. Last time I looked the Mirror API was not clean. I'm looking through FishNet API now and it seems less cluttered.
Any who, my day begins so I must hop off. Here is the feature page. https://fish-networking.gitbook.io/docs/manual/general/features @olive vessel
What issue exactly did you have with Mirror?
I don't need a feature list, I donated to FishNet you know
I don't think these really change the hosting situation
Is it whining about using Mirror LTS?
I imagine most asset developers would like you to use non buggy versions of Unity ๐
Well I think most people would warn you about that...
If it's just the latest tech release, Mirror is probably fine
Generally you want high amount of testing in projects that matter
In your situation, it's probably fine
You should test the hosting from a browser instance thing asap btw, since that has a high chance of screwing with your plans
MLAPI being released or not probably won't change that situation
Best case they offer free relay servers
If you are new to game development, singleplayer is definitely preferred.
That is how a relay server setup would work, yes. You can host server just fine assuming the person setting up the server knows how to change their network settings, which is generally beyond 99.9% of users.
To open the port
and have the port open, yes
Not just system, but generally router settings
You can see the general process by looking up how to setup servers for other games, like CS, Minecraft, etc.
@weak plinth you can use mirror + epic online services for free relay server (player hosted games)
Thats about all you can get for free though
Yeah its completely free. Ridiculous I know lol
Check out # epic channel in mirror discord
Yeah just Google mirror discord you should be able to find it. Can't post invite links here i don't think :)
Lots of people have been using it, it seems like it works good
Im working with MLAPI, and im making a simple multiplayer fps. I'm having issues with each player controlling the correct character, for now either everyone is controlling everyone or (after some attempts to fix it) everyone controls the same character.
remove nonlocal cameras
what does that mean?
May I ask, which objects should be server - side and which client side in an rpg on dedicated server? It's just, I got an error - "disconnected cause of clients logic" - what could it be?
Thanks, it worked well!
I'm having another problem: how do I change the parent of the spawned object? I need to attach a spawned item to his player's prefab, but seems like instantiating it with the player's transform doesn't work: the item is correctly set as a child object in the Server/host, but the clients keep the item without a parent.
Easy
Well it is easy if I can explain right
Basically you wanna in the script of the object type
gameObject.transform.SetParent(the transform of the object you want to parent it under);
Yeah, it doesn't work
It changes that for the server, it doesn't change that for the client
It's on a ServerRpc, so yes
Send it to a client
[ServerRpc]
public void EquipServerRpc(ulong clientId, int itemId)
{
if(equippedId >= 0)
{
NetworkObject player = NetworkManager.Singleton.ConnectedClients[clientId].PlayerObject;
var item = Instantiate(InventoryManager.Instance.itemPool.getItem(itemId).equippedPrefab, player.transform.GetChild(0).gameObject.GetComponent<PlayerController>().objectInHand.transform); //This works for the server
item.transform.SetParent(player.transform.GetChild(0).gameObject.GetComponent<PlayerController>().objectInHand.transform); //This also works for the server
item.GetComponent<NetworkObject>().Spawn();
item.transform.SetParent(player.transform.GetChild(0).gameObject.GetComponent<PlayerController>().objectInHand.transform);//This also works for the server
}
else
{
NetworkObject player = NetworkManager.Singleton.ConnectedClients[clientId].PlayerObject;
Destroy(player.gameObject.GetComponent<PlayerController>().objectInHand.transform.GetChild(0));
}
}```
So there isn't a way to set it in a server?
Do I have to call a clientrpc and set it in every client?
How do I select an object with the networkId?
I mean, I have to tell the client which object has to be set where, but I don't know how to select the object (knowing his NetworkId on serverside) and the docs don't explain it
Yeah
Ok I can't even select different player prefabs outside the owner's player prefab, if I'm not the server. Is there literally any way to select an object in MLAPI with a network id/client id? I need to use it in a client rpc, so no "ConnectedClient[]" dictionary can save me...
Well, yes?
I'm trying to equip an object
so every client has to see that a player has equipped the object
since networkobject can't change the parent (outside of the local space) and, in every case, a networkobject can't have another networkobject as a parent, I must spawn every object locally
but without access to ConnectedClients, as a client, I can't tell to every client "ok spawn this object at this player"
I can do that only in the host, because he's the server
Damn MLAPI is confusing
and it's really young, so no tutorials/posts in the forums can help me T.T
I'm still confused on how to use MLAPI at all too.
Even I've followed the documentations, I still have yet to understand how I can get the client to join the host ๐ฆ
No idea what you're trying to achieve but could you briefly tell me what exactly you want to do with MLAPI?
I'm trying to create a network lobby for players to join.
You have access to a server?
void OnEnable()
{
if( !ClonesManager.IsClone() )
{
NetworkManager.Singleton.StartHost();
}
else
{
// this should connect you to the host?!?
NetworkManager.Singleton.StartClient();
}
Debug.Log($"Lobby On Enable - IsClient: {IsClient} | IsHost {IsHost} | IsServer {IsServer}");
}
On one project, It starts up as a host, which shows all three variable true. On the other project it joins as a client, which only client shows up true. Yet I have event handler that should display a message stating that a player has joined the host
So I feel like there's something lacking out of that documentation. I'm trying to check out Boss room example Unity provide and ingest information from there.
I'm afraid I can't help with MLAPI but I wanted to ask if you're interested in trying my library that I'm working on
It's not player hosted but it does allow players to make/join rooms
I'm curious if I managed to make it simple enough so people are willing to try it
Let me know and I'll help you get going. Multiplayer is complicated as is and all the options don't make it easy I can imagine
Feel free to dm me
[Client]
void Update()
{
SpawnCommand(hit.point, cam);
}
[Command]
void SpawnCommand(Vector3 position, Transform cam)
{
GameObject enemy = Instantiate(enemyPrefab);
NetworkServer.Spawn(enemy);
}
I'm using Mirror, and attempting to spawn an enemy on the server when the user presses a key (For testing, I'm just doing it in Update() on the client). This is giving me the following error:
Trying to send command for object without authority. SpawnEnemy.SpawnCommand
UnityEngine.Debug:LogWarning (object)
Mirror.NetworkBehaviour:SendCommandInternal (System.Type,string,Mirror.NetworkWriter,int,bool) (at Assets/Thirdparty/Mirror/Runtime/NetworkBehaviour.cs:115)
SpawnEnemy:SpawnCommand (UnityEngine.Vector3,UnityEngine.Transform)
SpawnEnemy:Update () (at Assets/Scripts/Enemies/SpawnEnemy.cs:24)
Line 24 is SpawnCommand(hit.point, cam)
So you need authority to run a Command, right? But how would I do something based on user input without the user having authority?
Got it. Since it spawns for everyone, it doesn't matter who actually presses the button, so I just replace [Client] with [Server] and put it all in there
It's working correctly here. Can you show me the place where you call the callback to "welcome" the new player?
I've done a lobby in my game so I can help you!
(however I didn't add the password, so if you want that you have to look it up online)
By the way, with my problem (selecting a networkObject by networkId, in MLAPI) I found that the docs have this:
"When a NetworkObject is considered "Spawned", it is replicated across the network so that everyone has their own version of the object. Each NetworkObject gets assigned a NetworkId at runtime, which is used to associate two NetworkObjects across the network. For example, one peer can say "Send this RPC to the object with the NetworkId 103", and everyone knows what object that is."
But there's not written how do to that T.T
I followed tutorial how to do quick matchmaking but void OnJoinRandomFailed didnt works (i am using photon)
i did it it works
Hey how can I call an RPC function to only yourself instead of all players? in photon
Can't just call the function directly? You can pass in target player instead of using RpcTarget
Anyone using LiteNetLib here ?
I added it... under plugins but the namespace is not recognized
Any ideas why ?
Is there a way to synchronize only the rotation of an object ignoring the position, with my networktransform component? (MLAPI)
I need to sync the rotation of a child object, but if I place a networktransform the position of the child object is "delayed" against the position of the parent...
LiteNetLib seems a bit over engineered. lots of threads, locks, complexity.
you might be better off with kcp/enet/etc.
Is unity mlapi out?
Preview versions are available
Hey how would I change a float value which is a value of the player's weapon accordingly depending on which weapon the client chose
Please is uNet still working??
UNet is deprecated, you should look into other solutions like Mirror, MLAPI (Netcode for GameObjects) or Photon products
May I ask, how to fix this code? I think I understand that to fix it I need to somehow reference that the player is local while not on the player but on the server... but how?
[Command]
private void CmdUpdateL()
{
if (isLocalPlayer)
{
StartCoroutine(AttackCo())
}
}
--------------------------------------------
[ClientCallback]
private void Update()
{
CmdUpdateL();
}
I'm getting the following error
NetworkServer is not active. Cannot spawn objects without an active server.
whenever I try to call NetworkServer.Spawn(obj);
what am I doing wrong?
i'm using Mirror btw
the player with this script on it has client authority
only server can spawn networked objs
you need to send a command to the server or have the server context call it
ok that got rid of that error. I'm now getting:
apparently Mirror's documentation is confusing and doesn't explain very well. How do I access the element in either SyncDictionary<> or SyncHashSet<>? https://mirror-networking.gitbook.io/docs/guides/synchronization/syncdictionary
Using Mirror, how can I find what user pressed a button but still do something on the server? I need a script on my GameManager to spawn an enemy at the center of the screen when a user presses E
If I do this using a command, I get a "tried using a command without authority" (That text may be incorrect. I've been tinkering with this for a few days so I can't remember the exact text) error, but if I use a [Server] thing, I can't get the user that pressed the button
Thanks I will do that
How's that confusing? You can just do mySyncDict[keyName].Whatever if it's a class/struct or mySyncDict[keyName] if it's just values
Hash Sets are something I am not fluent in, but SyncDictionary should be pretty straight forward ๐
It wasn't letting me do that earlier. I think the issue was that the name was being ambiguous.
HashSet is just Dictionary, but only based on unique property.
E.g. Dictionary<string, item>, whereas HashSet<Item>
Identical elements are prohibit in HashSet.
Use a command function type to instruct the server to carry out something.
private void PollInputs() {
// Example.
if(Input.GetKeyUp(KeyCode.E))
LePushButton(true);
}
[Command]
private void LePushButton(bool selfDestruct) {
// Code here runs on the server world, do whatever.
if(selfDestruct)
Oops();
else
DoSomething();
// Tell the client we pushed the button.
LeButtonPushed();
}
[ClientRpc]
private void LeButtonPushed() {
// Explosions go here.
}
ah right
I get the "Trying to send command for object without authority" error when I do that, whether or not client authority is selected
Seems to me like you're likely missing either a "isLocalPlayer" (I think it might have changed wording in Mirror) check as it seems like another object is also picking up inputs from the local player (which is bad - short-circuit any input polling for non-local players or you may get really weird behaviour)
If I use that, it just doesn't run at all
I'd need some more info, where is your script attached to the object?
on the player, or camera?
The script is on the GameManager object. It's SpawnEnemy (It's enabled at start)
And Game Manager is owned by whom?
The server? Or the client?
If it's owned by the server, then of course - you have no authority (access rights) to run that command.
Client
You'll need to move the spawn script to your local player object.
That's why you're getting that error.
You're trying to call a function on a object that you have no control over, because Game Manager is "owned" by the server/host
This is on GameManager, a script attached to the Game Manager object. OnJoinGame() is ran by the players when they join
How would I allow the clients to control it?
That's from my testing
OK
Alright, so tell me your end goal, spawn a object on the server, right?
Yeah, at the center of the sceen of the user who pressed E
Do you need the GameManager to run the spawn code, or are you happy for me to condense it down into just a single script?
So you attach and boom, you can spawn enemies from the player?
I would prefer a solution that can be run from other objects, so I don't need 400 scripts on the player object
Alright. I'll work my magic. Note that this will be super crude but it'll work.
@swift epoch does the client require authority over the spawned object?
Not this one in specific
ok, i'll omit that.
Alright, testing locally now
Done.
So basically, I have two scripts. One is your game manager that does the server-side spawning. The second is a script you attach that then tells the server's copy of the player object to tell the game manager to spawn a object at a random position. I'll throw this onto a Gist for you. I have sprinkled some comments that should be easy to follow.
Tested and zero spawn problems.
Thank you so much
ExampleGameManager: https://gist.github.com/SoftwareGuy/82fb8e9a03169f67615779d51dfe37bd
ExampleSpawnScript: https://gist.github.com/SoftwareGuy/2f88ca0a384cd9ddd2d499333369d70e
Bonus, comes with a working scene. I use Mirror LTS, so it should work fine. Throw this code in, build that scene and as a client, press E. Both server and client should get cubes.
I'll have to test it in a few minutes. Thank you again
It's super basic but you could very well rig it so you grab a raycast position from your camera
then tell the server hey i want to spawn it there
but yeah, the basis is there. Definitely good enough for prototype
I was finally able to test it. It worked perfectly!
Anyone work on Nakama architecture/networking have some time for a few questions?
Glad to hear it, Pinto ๐
btw u dont have to do
gameObject.GetComponent
u can just do GetComponent
Hey how do you synchronize float values so if player 1 has the float value set to 3, other players can see his value set to 3?
Hello guys, i hope you have a wonderful day
i used Photon to make my first multiplayer game prototype
Anyone knows why Players positions are a little bit off in different clients? (Compare using the grid on the floor)
Thank you
Does anyone know the official unity mlapi discord server? the links on the unity forum and blogs are broken.
It's on this page: https://docs-multiplayer.unity3d.com/
This site provides Unity Multiplayer documentation, references, and sample code tutorials.
Ah this one is working, thanks alot ๐
Link also in the pinned post
Hey guys, is it possible to override OnLeftRoom() in photon?
I need help with a problem I can't fix.
If my player disconnects I want to destroy his Player GameObject, if he leaves with button It works. But what if someone closes the game and disconnects by that action.
How do I get his Gameobject?
And destroy it ?
With Photon btw
Using MLAPI, I want to send a lot of information from the host to 1 client. Right now I do a serverRpc to get all the hosts information I want to send, then I do a clientRpc with if(!isOwner) { return; } so the client that sent the serverRpc gets all the information. But I want to know will the other clients be sent the information too because I'll be putting all the info in the method. I know they wont do anything with the information but I want to know if this way is the best way. Like I don't want to call clientRpc with a lot of info to every client, just 1. IDK if the method with a lot of information will be sent to everyone. Hard to explain. I just don't want to use a lot of bandwidth sending all this information to every client just for them to say, oh, return. I just want 1 client to be sent to and receive it.
Oh, I didn't know that. Thanks!
This is a script that creates a "dumb" enemy AI. It just constantly moves toward the nearest camera. It's attached to the enemy's prefab so only runs while one is spawned
For whatever reason it creates the following error on the client
[Server] function 'System.Void MovRotScript::Update()' called when server was not active
UnityEngine.Debug:LogWarning (object) MovRotScript:Update () (at Assets/Scripts/Enemies/MovRotScript.cs:25)
Can anyone help me figure this out?
Putting if (!NetworkServer.active) return; in Update() did nothing, presumably because the actual Update() function itself is still running
try put if(NetworkServer.active){put everthing inside}
how todo these cool code snippets?
That'll give him the same error
Like he says the update function would be called regardless and print that error when server isn't active
// CODE
It's the backtick. On the same key as ~
Not familiar with that API though so no idea about how it works
Looks like Mirror to me but not sure and haven't used it before
It is Mirror. Apparently it's very similar to UNET, though
Yep. Tried it anyway and it gave the same thing
So do you know where Update is being called from initially?
The Server attribute gives me the suggestion that it's automatically called from somewhere
I forgot to mention that error occurs every frame
Double click the error it might lead you to where the error check is taking place and perhaps give you some more information
This script exists in a vacuum. Nothing else refers to it and only refers to its own RigidBody
It's a NetworkBehaviour so I'm kind of assuming it's being registered somewhere by Mirror
Leads to the first line in the Update()
Alright nvm then it was worth a try ๐
Oh yeah, most likely
Do you know what the Server attribute does?
Without any background I'd think it's being called every network tick by the server but I could be wrong
Or let me put it different. What would happen if you removed the attribute from the method?
I can't find any documentation on what that error actually is, so I don't know if that's what's happening, but if (!isLocalPlayer) does nothing
You might find it on their github
That runs the function on all clients and the host independently. That works, but if they become desynced it could cause issues
So if I understand it correct, you'd use this for something like an NPC that nobody owns but the server?
Yeah
Does this script or object have any input scripts that allow it to function? Otherwise you might be able to get away by removing the Server attribute because nobody could control it anyway
Just trying to think outside the box though since I have no idea how Mirror likes you to do things
I could do that, but then on one player's screen the enemy could be walking in one direction and on someone else's it could be walking somewhere else
Well it'd be rare
But say the enemy collides with a player, and this packet is lost for one player. Well now they're desynced, so it could be way off somewhere else for that one player now
Does Mirror have a NetworkObject component (similar to PhotonView)? If so then you should be able to check if you're the owner or not
yes its called network identity i think
I believe NetworkIdentity or NetworkTransform is the equivalent
btw has anyone tried mlapi? i have been looking at a few solutions (mirror and photon) but not sure which to commit to. i'm looking for something that can allow me to do server auth stuff but not cost an arm and a leg. any suggestions?
Alright so maybe that could be an alternative way to check whether you're allowed to control the object or not. What this means in terms of synchronization is a completely different matter however ๐
I've only tried Photon before deciding I'd make my own networkingsolution
๐ข
Completely different emotion conveyed by that edit
I tried using ServerCallback instead of Server. ServerCallback isn't supposed to create an error when a client tries running it. This stopped the error
So I believe the issue is just that the client tries running it as well. I guess that actually gives somewhere to start
If it still does what you expect it to do without the error then it should be good enough I suppose
the best way to fix networking in unity is to simply ||use unreal
||
You know there are tons of networking options out there you can choose from right. If you think you can/should only use what the engine gives you then I don't know what to say
That is so true. You think unreal is better but to implement the networking would be harder in my opinion. Also networking in unity is rather easy you just need to find the right solution, and actually take the time to learn it and not complain bout it after watching one YouTube video and not getting angry bout trying to get help back from your problems instantly ๐
Using MLAPI. client calls a ServerRpc, Will the ServerRpc find the hosts data if I run programming here? Or do I need to call a ClientRpc in the ServerRpc and do if(!isServer) { return; } then get data I want from host? If this makes sense.
Hello. How can I get all player position in a multiplayer game using Mirror?
Thank you.
transform.position ๐
you can get all spawned entities via NetworkServer.spawned
Wouldn't they need something similar to if(object.TryGetComponent<PlayerController>()) to distinguish players from non-players?
hello guys,I want to learn how to make a side-scrolling mmorpg, but I canโt find a suitable article to learn server related information from the beginning, Can anyone recommend me any articles?
pick any of the available net solutions and check out their examples
itโs not that difficult anymore compared to 5 years ago
MLAPI. Open world game. Im trying to send 200k bools to a client to disable any changed objects in the world using Rpc but it says limit 1.4k... And im not using .Spawn() because clients cant collide with the objects. Bit lost on what to do.
200k is a lot. You will probably have to use a custom message for that. Is there no way you could send this information in another way like only send the objects which are in chunks close to the client?
Idk how to do that. But i can look into it.
This is only 1/5th of my world done. Im scared now lol.
must i use networkvariable for client+server side variables?
If you want the variable to be synced, yes
and unless there only client sided?
Just a normal variable then
so i must all variables change to networkvariables
If you want all variables to be synced
So the answer is no, you likely don't want all variables to be synced
the the game need (postion, stats and the all other)
Position is handled by the NetworkTransform
Health is a good example of a NetworkVariable
Not sure what that means
There is a Video Tutorial covering some of the concepts covered in this page here
When in doubt, check the docs
May I ask, I'm trying to follow additive scenes and there's a line that says "add subscenes to the list" so I wanted to ask - does menu scene count as a subscene? then what about the main scene? I have three scenes in my project, main, subscene and menu.\
In order to load in a scene additive or not the scene file must be added to the build settings scene list. After that you can load it in and out at will. First one in the list is your starting scene Unity loads on app start
no no no, sorry, need to clarify, I'm using mirror and I'm talking not about build settings but about this line
that creates a list where I can add and remove scenes.
but I have no idea what counts as a sub scene and what not
so its main game scene and subscene... or is it menu and subscene? I'm confused xd
or even all three of them
Whatever is the first scene loaded in by Unity would not be a subscene. So maybe you start with like a bootstrap and then MainMenu, Level1 etc are subscenes
The first scene that is loaded is menu so I think I will add main game+subscenes to subscenes... Ok, thank you ๐
That would be how I interpret it yea.
Might be worth though having like a bootstrap scene just for loading additively into because I assume after your game you will want to return to the main menu
So, I have this error "the scene object down hit box has no valid sceneId yet" and don't know what to do with it.
Can somebody please help?
Has anyone have experience getting data from google fit to use for your game?
May I ask, how to fix Prefab 'Player' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object.
if scripts of children depend on identity?
Hey all, i have a class that inherits from NetworkBehaviour but it doesnt know the [Command] attribute. Does anyone know why?
What networking solution?
?
Hey, for my multiplayer game I have a arresting mechanic which players can place handcuffs on other players, making them unable to move. How can I make this system?
You could have some network variable like isHandcuffed and if it's true, don't let them move
Obviously this would only be set on the server
Client just needs read perms
In your input logic, you'd just do like...
if(isHandcuffed) return;
if it's a function that feeds input data back to whatever.
can some one help me how i make character selection in Unity Pun ?
@weak plinth Create CharacterDefinition ScriptableObject that has all the information about the character and give it an ID of some kind, most likely int. Send that ID whenever you want to communicate a specific CharacterDefinition over the network. Receiving clients can go through all the CharacterDefinitions to turn the ID back into a CharacterDefinition.
You can apply this sort of setup to a lot of things, like maps, items etc.
At least when it comes to static data.
Put helpful debug logs in each method to check what is being called
Iโm trying to create a kill feed/kill counter with Photon PUN 2, does anyone know a really good tutorial/know how to go about it and could help me with it?
I added a debug.log in every function and this happened
waits patiently
Tells you to stop roleplaying and use Google, that is a well documented thing you want to do
.-.
Hi, Does anyone know how I can check if a player is on an internet site? It could be any website, I just need to know if it's there.
they literally said Debug.Log in that page?
omg sorry
You havenโt classified the room options
how can I do that?
Try something like
RoomOptions room = new RoomOptions();
And then when you create a room pass through room
How can I connect to a ngrok tcp tunnel?
Hey how can i change enums throught all clients when a player presses a button?
Depends on the networking solution
You can use RPCs or NetworkVariables, depending on networking solution there will be subtle differences with how you implement them
I use photon
Then you should look into synchronising variables in Photon, not sure how Photon does all that tbh
OMG IT WORKS!!!! tysm
IM making photon networking and it it a rigid body locomotion base where you use the force of your hands to move around and when the 2nd network player spawns there is no model attached to the rig
do u have a photon view on ur player?
Hi all, I'm trying to use photon fusion's NetworkCharacterController in place of the default Unity CharacterController to get an extant character asset working in a multiplayer setting. Everything's working smooth, just trying to parse a method that gets the platform the player is currently standing on. In the original script it used MonoBehaviour's "OnCharacterColliderHit" to pull the hit.Collider.Transform. Photon seems to have a similar method for its networkCharacterController (OnCharacterCollision3D) and I'm trying to pass the same along, and I think my error might just be one of syntax. Am I calling this method correctly?
Hello. I'm having some issues figuring out the best solution for networking.
A little background knowledge: I'm trying to start working with Unity (I now have about a week of experience with the UI, package manager, creating various things like prefabs and materials, etc. and can say I feel comfortable working with GameObjects, scripts, and basic interactions between parts.) I am trying to create a 3D game from scratch. I have another game in 2D, but it was written in TypeScript with Angular, Node, and WebSockets. I use a couple libraries there which make networking absolutely easy.
The problem is, I can't seem to figure out the best solution when it comes to Unity. Whereas in my other project I can simply send and receive updates to/from the server based on actions on either and invoking a simple function within the client or the server's main objects, this doesn't seem to be at all the case with Unity.
I have now went through a few options but the biggest thing holding me back is persistent data. I cannot find any solutions (except writing my own sockets and networking code from scratch and I don't have enough experience to do that yet.)
I've tried Photon, which works extremely well, but has no persistent data. I've tried MLAPI but, well, I think we can all agree on that being an issue, although it did work partially. I've looked into Mirror but haven't used it yet, as it looks similar to the others and still can't find any info on storing persistent data.
The requirements for the solution would be:
- Storing persistent data.
- Spawn them in the last position and map they left in, and with which character they selected (character customization) before joining the game.
- Mostly just normal data types. The biggest thing I think I would need to send is the different character options they've selected (an object containing ints and strings and maybe an array of ints or two) and the position in the game, action taken and basic chat.
Once I have networking, I think I will be able to continue on my own for most of the rest of the development, but networking is a base requirement for the game being made.
I'm not used to asking for help (as I try my best to learn everything on my own,) so if this is long or formatted incorrectly or anything, my apologies. Also, if it's easier, you can DM me to discuss this. Any help with this is appreciated.
Answered your question in our own Diwcord
Discord
@ancient lantern there's a reason none of the mentioned libraries have persistent data, because that's typically handled by the server (or even the client itself sometimes) rather than the framework. These frameworks give you means to send/receive data, but it's up to you to decide the conditions when this should happen. You most likely want to have some kind of database to store persistent data, where the database is the storage unit and the networking framework is just the medium to transfer it from A to B.
I think where I get most confused is by the fact that most of the implementations I see have a single Unity project that contains both the client and the server inside of it, otherwise you're writing it from scratch (I don't have enough experience for that.) I was looking for something that I would imagine is more performant than that, and having to fork/clone/write build scripts that produce larger code than it really needs to be.
Those kind of projects in my opinion are for demonstration purposes only, but you're absolutely right because in production nobody would ever use such setup because it's not efficient enough. There is quite some abstraction involved to get many different systems working together, and having a server for the sole purpose of doing database stuff isn't unheard of. It all depends on the size of the system however, main take away is that database often stands on its own and knows little or even nothing about the game itself. The server does the interaction with it, and gets/set data from/to it when it needs to. It doesn't even need to be that complicated either. A database could just be some kind of data structure in your server application, but in normal circumstances when the server shuts down the data is lost (unless you write to disk).
That strongly depends on what you are trying to build
@ancient lantern you get games like Fortnite, Pubg, CSGO, Valorant, where server/client are written on the SAME project
the server runs almost same code as client, etc...
The most common case (if you can call that common) where you write separate projects for server and client are actual MMOs, because the engine code would not scale to the sheer number of clients you need to handle.
But that is far from what most online games do...
As the others stated already, persistence is normally dealt with almost agnostically to what is the solution you are using for online synchronous gameplay (the libraries you mentioned deal with the later only).
Also notice photon is a company, not a product, so I assume you were talking about PUN2. I suggest you look into the higher end solutions by photon like Fusion and Quantum.
Just one point Swanson:
but in normal circumstances when the server shuts down the data is lost (unless you write to disk).
The point of the DB is to NOT loose the data
Otherwise you don't even need the DB
If the game is relatively simple and PUN(2) serves your needs you could also rent a webserver which can store data for you, and interact with it through http requests
You're right I was merely trying to make the point that a database can be in memory only as well
in short:
- mmos, server is normally a separate project, not using Unity
- regular games up to 200 or so players, server is normally a unity instance, using same project (or deterministic, which does not need an engine server - special case)
- in BOTH, DB is a separate thing, used to persist game state when servers are shut down...
yes, that is actually a good practice
db in memory is a good way to simplify the implementation of these, as you can rely on SOME of the DB features (like searches) for some gameplay stuff, arguably
If it's not super crucial data then it could be sufficient and it's super fast and easy to do
yes
Just wanted to add some more info I hope is helpful. You are giving good advice...:)
Thanks I appreciate that. There are plenty of choices for him and it could be very simple depending on what his requirements are
Well, ultimately I think I will need a high performance option in the future, I may get upwards of 50-possibly a few hundred, maybe more, on a single (large) map and server at once. Something like Silkroad Online (the real old game, not the other site) where you spawn in and there's just people everywhere.
The persistence is needed because there will be character customization in the game, as well as chat, and other player data. I also just really don't want to limit myself in the early stages of development and then have to rip out the old networking and replace it later, introducing bugs.
Also, it surprises me- If that's true- That those big titles actually build in the same project like that. I mean, the server/client code in my other project is technically in the same project, but the TS and Angular compiler pick and choose which files and components they actually need during the build time. Unity has no apparent method of "just include the server stuff" during build.
Also. What about the DB stuff being on both client and server? Would a simple "!IsServer" check be enough to disable DB on clients, or how would that work?
The database will be for the server only to talk with, then the server forwards any information to clients when needed. Clients should not ever have access to this database
Another question with it both being client/server in a single project, is what about decompiling and looking at the code? It also seems to be a bit of a security risk if I make a mistake.
That's a never ending battle and speaking from experience, not even having to look at assembly code is going to stop someone if he really cares to break stuff
You want to prevent exposing critical elements to the client
So best they can do is make (bad) assumptions on how something works and even if they know how it works they will have to break into the server to exploit it
But in popular games people will cheat, it is what it is. You can go out your way to prevent that from happening but it's a tough battle regardless of what you try to do about it
So host DB on machine with server (separate process like MySQL or something,) Unity code only contains access to it (I was thinking about using the built-in Unity storage if I go this route but let's not go there yet,) use environment variables, arguments or something, and then no matter what the client does, it's firewalled, I guess? Oh yeah, and does Unity have support for .env or anything to store credentials? >n<
Unity uses the .net framework which allows you to create any file you like
And yes, host database on the/a server where nobody would even know of its existence
However don't get caught up on the idea that the server has to be a unity instance as well. The only reason I can think of why you'd want that is when you want the server to do all the physics, this is also the most expensive way of doing it
I have a physics based game but the server itself knows nothing about physics, it's a console application that pretty much knows nothing about unity at all
I've yet to see however how many clients it can serve
It only uses a couple of megabytes of memory and barely any CPU which is a good thing
That's exactly what I'm aiming for, really. Just a console (I know about headless Unity builds but still, Unity backend) that serves clients. As for physics, I did actually want some sort of anticheat at some point added, but nothing more than "they just can't teleport across the map" kinda thing.
But as you can see there's so much to it and it's impossible for a single person to walk this minefield without getting hurt. Try to learn from your experiences and see where things fall short, is all you can realistically do at this point
Expect to fail multiple times for unexpected reasons
Yeah I personally don't feel much for doing all this anticheat type of stuff, I do the low hanging fruits because I don't have the expectation that my game will be popular all of a sudden. There's so much more for me to learn about and getting stuck on fighting cheaters isn't much fun
I believe more in giving some trusted players privileges so they can deal with cheaters when needed, these players who play your game a lot are incredibly valuable
When you have to worry about cheating you already work for a company with popular IP and get a 6 figure salary
That's the dream we chase ๐
If I have learned one thing from my other game and running Minecraft servers, it's that you need to expect cheaters eventually. Lol. I try to be thorough in the beginning instead of worrying about it when the server is on fire and those players can't play anymore.
Yeah if you have more than just a handful of players then you can expect someone to try and cheat
Tilting windmills though
you can easily prevent sensitive code from even compiling for the clients by using compiler flags
like #IF SERVER_BUILD, etc
I mean do the reasonable thing, server authority and such, but donโt worry about stuff that hasnโt got solutions in your reach
yes... exactly the above
For example, aim-bots are normally something you do not DEAL with when working with NETCODE
Needless to say not even most of the popular titles have their shit together, they made a wager that they'll profit more by just not putting in all the effort to prevent cheating, they are already working on the next title and repeat the trick and everyone buys into it
If you ever will deal with that, you need to involve: memory anti-tampering and/or pattern-recognition on server
Client&server as separate projects is adding a lot of wasted effirt imo
but apart from aimbots, most other cheat stuff can be dealt with by doing proper server authority, etc
xD
Anyway, I've pretty much got a plan in mind, now my only remaining question, is Mirror still good, or should I use another stack? I tried MLAPI but it's just painful and incomplete and the documentation matches that state.
Also didn't know that Unity had the option of build flags in the code like that, I'll have to look into that.
My biased suggestion is: try photon fusion
disclaimer, I work at Photon
Because fusion has things like client side prediction, snapshot interpolation, lag compensation, all turnkey
Mirror is good for low aiming projects, MLApI allows you to get more serious. Custom is the real way to go
I did consider the WebHooks method with Photon actually. But it seems like an extra server to me.
that is not something we at photon recommend at all...
WebHooks for dealing with authority is really not related...
How else do I store persistent data while hosted with Photon?
If you are worried about server authority, go for Fusion
that is not even meant for persistence
As everybody said here, persistence has not much to do with netcode gameplay
It's a different problem
Yes, but the server must have the means to actually write to/access a database.
yes... but that is mostly Unity, does not matter which netcode solution you choose
to be clear, all the products below let you run a Unity instance (dedicated or player hosted) as authoritative server:
- mlapi
- mirror
- photon fusion
- photon bolt (legacy)
- custom stuff
They all have their specifics...
But storing whatever is the server current state in a DB, is not really different
no matter which one you choose
But if I'm relying on Photon to host (or using the standalone Photon instance) how can I have the server save data? If it's possible at all. I only want clients to connect to it, they save no data, it all comes from the server.
the differences between these will be about the NETCODE features they offer out of the box
But if I'm relying on Photon to host (or using the standalone Photon instance)
Please, be clear here...
You mean you are running a custom photon server + Photon Realtime or PUN2?
Notice I'm not even recommending these anymore (I'm one of the lead client SDK engineers at Photon)
PUN is a legacy product, and if this is a new project you should consider Fusion instead...
You can download and develop for free, and it offers the same type of CCU plans as PUN/Realtime
If you are considering go with one of our products, I strongly recommend you try Fusion, not pun
I was indeed referring to PUN2. Also I would like something free, at least during development and before release (dunno if Fusion is free.) But the question remains, how to get any Photon server to connect to a database. Is the code modifiable in the standalone instance, and if it is, why is there a 100 player limit, unless that's not applicable to Fusion.
Regardless of what type of framework you use (except relay based ones) your server is a standalone application running on a machine, and that machine can run any kind of software you desire. Then it's a matter of accessing the database API from your server application to get data from it
With relays you have little to no control of the server it runs on so that's why it's not a real great option for storing state
In almost any other case you do have access to the underlying machine and can run whatever you need
I got really excited there, I thought, "yes. A solution. Finally my hair can stay in my head" and now I have more to look into with Photon. xD
Also with Photon PUN Cloud, the server isn't hosted by me at all, it's controlled by Photon and the rooms recycle by what I've read so there's no option of any persistence.
My server runs on linux, it allows me to install any software I need and I can run any dotnet code of my choice
PUN is a bad choice anyway cause it doesn't scale with many players in a room, which is what you want right
And it's relay based
I was under the impression by the "up to 50k players" on the site that that could be in a single room, but I could be wrong-
Not if they're all GameObjects
You need something more than relays to get what you want
Something that gives more control over the network and the machine
it's free to download and develop, just check on the website. Also ccu plans are same way as realtime/PUN
And Fusion by default is client/server with full server authority (with client side prediction, snapshot interpolation, super fast delta-snapshots or eventual-consistency, lag compensation, etc)
With server being a Unity instance... room is used for:
- punch-through connection signaling + relay fallback for client/server messages (so even if server is hosted by a player, there's no need to port forward)
- handle host migration (being worked on)
You opened up a rabbithole with your question ๐
Kinda unrelated but I just found you on YouTube and am about to watch your 45 minute video on Fusion. xD
But in the end, I guess I have a plan now. I will look into Fusion and choose between that and Mirror. I think I'll build it in a single Unity project and add a build script. Unless someone here wants to teach me about MLAPI. Lol.
I've seen people talk a lot about MLAPI this past week but none seem to know how it works yet ๐
I mean. It's only been in development for how long now? Lol. It's pretty good compared to Mirror, if everything actually worked.
Or if there was better documentation.
I've given up trying all these frameworks, they have a lot to offer but quite some time is needed to figure out how they work
In my case it was less work to make my own dedicated framework to get the things done I see as important
Yeah, in the future I'm definitely going to have to spin my own. But that's for later me to deal with. For now I'm just trying to get some base ready for release.
Granted that I've spent some time researching otherwise I would not even consider this
my piece of advert: neither mirror nor mlapi have anything close to: tick-accurate simulation, fast delta-snapshots, snapshot interpolation, client side prediction or lag compensation... (which are built in features in fusion)
You'd have to write all this yourself, and these are not simple...;)
Yeah total pain in the back
not to mention other things like constant GC allocations and performance...
BUT
You should always try and choose what you think it's best for you
Even lag correction on its own is a pain while still making sure they don't teleport across the map, I know this due to TypeScript not having any great modules for that and my other game. Lol.
My framework does none of that except interpolation. My biggest pains were ease of sending data and low memory consumption
Anything else I can build on top if needed
Anything specific which we could improve? Where did you get stuck?
Code examples were a huge problem. They are very basic, and in some cases, non-existent.
Also there were some problems I had with things like imports and using attributes. When trying to use a Client attribute for instance, I couldn't find what to import or what class to use for it.
Code samples are a fair point, there is definitely a lot of improvements which we can make there. If you have a specific page let me know and I can take a look at adding a sample. Regarding namespaces that will be much simpler starting from the next version where everything will be under Unity.Netcode.
Thank you. I honestly really value someone that approaches people that could give feedback on things, and I really do have great hopes for MLAPI. :)
Anyways, thank you all for your help. I swear, you've saved me days of messing around with methods that would probably never work. If there's anything I might be able to do in return, give me a DM or something.
yw
just keep being part of the community. Learn what you can and assist others when you have good advice to give.
I've already been peeking at the other support channels waiting for something I can answer to. xD
Hi, im using MLAPI and really overwhelmed on how to create a P2P game (that also supports singleplayer) efficiently, should I have two states for my script? Say for example: my Bullet.cs script would have network functionality like: "if hit, explode, send to clients that it exploded", but if its singleplayer it should only be "if hit, explode"
Currently right now I have a game that works with a very large asterisk as I keep getting these weird desync issues and the entire game breaks and the server doesnt do what it shoud lol
but thats another issue for another time haha
I think what you'll need is an if statement checking IsConnectedClient.
Well yes im aware of how to check if i am in a multiplayer game, but im not too sure on the actual therory of it, should I make two states in my code where its like such:
if server
do this shit
if client
do this shit
if !client && !server
do this shti but singleplayer
because I feel like i am overcomplicating it doing so
but this is my first attempt at a networked game so this could just be me learning and doubting myself
I choose a different approach: i have a damage script that has a "multiplier" value, i set that multiplier to 0 for network clients but to 1 for the server, then the server just directly dictates/sets the damage value for each player
so no damage is being applied on clients by themselfs, only the server sets the damage for the client, then you don't have to worry about networking at all in the damage script
you also avoid desyncs as the server is the one true source of how much damage/exploded a player is
I'd think of singleplayer as just being a host with 0 clients connected. Code it as if it were a multiplayer game just don't let anyone connect while in singleplayer mode.
thats very helpful, thank you all!
the only question I have, apologies if this is naรฏve, lets say for example, I had an AOE Stun grenade, and the server would set the state to PlayerState.stunned on the player, what if the client lagged and had to wait 250ms for them to get that message? Would the client rollback to the servers state with positions?
so in my case I run all the clients as i would singleplayer, then there's a script that broadcast the state of the server (one of the clients that is hosting) to all the others and override any client differences
so basically as long as the input of all the players is reasonably fast, the simulation stays in sync, but yes dealing with lag in multiplayer is very difficult
.>
spam ๐ ?
Yeah, ive seen some people do things like sending the desired input to the server
(like W, A, S, D)
but with Networked Transforms in MLAPI Im not sure if thats what I should do
Right now what im doing is making the player move his own player gameobject on his client, fully client based non server authorative
but obviously that leaves a large door open to cheating lol
hehe yeah for me that decision was not really an issue, as i'll be happy if there's enough players for it to even begin to attract cheaters. I was planning to do a big post about my custom UDP networking code / scripts setup for a sort of code review, just FYI i'm definitely no expert on the matter, so take my advice with a grain of salt
I appreciate your insight nonetheless ๐
Is that similar to what you do though?
Player movement on the client?
and then have the player decide where he is rather than the server?
no for me the clients simulate physics combined with the current realtime inputs, then the inputs are send to the server, the server then broadcasts the input to all the players (excluding the sender ofcourse), then every 0,5 seconds there is a "keyframe" where the server broadcasts all the transformations and hp for all players, forcing a big sync up. With low lag those sync ups are hardly noticeable, with larger pings, you will see some players "jump". My next step is to fix up that jump by adding interpolation (slowly nudge the player to the server reported position over multiple frames) and add a tolerance (will players even notice that guy 50m away being off the real position by 1m). It only needs to be as accurate as the player needs it to be.
Thank you for the detailed explaination ๐
i used animation rigging on my character to hold the weapon and equip and recoil
the whole character was fully setup and then i made it a prefab
and then set up photon
but when photon instantiate the player
the whole thing is messed up
and then animation rigging isnt working
without Photon it was a perfect Player Character
but it doent seem to be good with photon
anyone know why is that?
im adding multiplayer to my game and whenever i build the game and my friends starts up the game it says that weve both joined a room but we dont see each other
Are you telling all clients that a position has been changed when you move?
yeah i watched a tutorial mine didnt work but his did
I'd doublecheck ur code then, its easy to miss small things that break everything
or if you want, you can start adding logs to the calls ur not getting to pinpoint the issue, for example in the server; log position update call, and then log the call handler in the client where you update positions in the client
well when i start the game up like we just not there can i see how many servers are available
ok @heady stump i watched the tutorial i used and when ever someone else starts the game up it says A new player joined the room
but theres no one there
thanks!
If I call a serverRpc and in this I do something, only the server will do it right? No client will do anything here?
yes, but if the server is a host, the host-client will, since it is also a server
Hi, how would you sent a message to a specific client using MLAPI?
Take a look at ClientRPCParams / TargetClientIds https://docs-multiplayer.unity3d.com/docs/advanced-topics/message-system/rpc-params/index.html
Both ServerRpc and ClientRpc methods can be configured either by [ServerRpc] and [ClientRpc] attributes at compile-time and ServerRpcParams and ClientRpcParams at runtime.
My MLAPI needs are different I'm trying to figure out object visibility. If I have instantiated objects can I hide those objects from the local host in the same way that connected clients can be denied getting a synced copy of it with a CheckObjectVisibility function call? My local host client seems to see everything.
Is it nessary to not instantiate any rendering objects on the host system except the ones I explicity want them to see?
or could I simply set them inactive without this interfering with what another client sees?
You could turn just the renderers off
Ummm I made this targeting system for my Among Us game but u end up targeting urself (with the ability) (I am using Photon btw)```cs
Player FindClosestPlayer()
{
float DistanceFromNearestPlayer = Mathf.Infinity;
Player closetsPlayer = null;
Player[] allPlayers = GameObject.FindObjectsOfType<Player>();
foreach(Player currentPlayer in allPlayers)
{
float DistanceFromPlayer = (currentPlayer.transform.position - this.transform.position).sqrMagnitude;
if (DistanceFromPlayer < DistanceFromNearestPlayer)
{
DistanceFromNearestPlayer = DistanceFromPlayer;
closetsPlayer = currentPlayer;
Target = currentPlayer;
}
}
Debug.Log(Target.Name.text);
return closetsPlayer;
}
Well, you need a check inside the foreach loop, if currentPlayer is localPlayer?, continue;
Idk how Photon lets you check if this is the local player
ty
i used animation rigging on my character to hold the weapon and equip and recoil
the whole character was fully setup and then i made it a prefab
and then set up photon
but when photon instantiate the player
the whole thing is messed up
and then animation rigging isnt working
without Photon it was a perfect Player Character
but it doent seem to be good with photon
anyone know why is that?
please ping me when someone responds
Why are so many of the links to the MLAPI docs broken?
Which links?
A lot of the google links are dead pages and ~~ the replacement pages that I find using the search bar dont contain the stuff on the google preview~~
Oh that sounds like something in the SEO is broken ๐. I'll let the docs team know.
thanks! helping everyone!
How can I modify this FindClosestPlayer function to find the SECOND most close player instead? ```cs
Player FindClosestPlayer()
{
float DistanceFromNearestPlayer = Mathf.Infinity;
Player closetsPlayer = null;
Player[] allPlayers = GameObject.FindObjectsOfType<Player>();
foreach(Player currentPlayer in allPlayers)
{
float DistanceFromPlayer = (currentPlayer.transform.position - this.transform.position).sqrMagnitude;
if (DistanceFromPlayer < DistanceFromNearestPlayer)
{
DistanceFromNearestPlayer = DistanceFromPlayer;
closetsPlayer = currentPlayer;
Target = currentPlayer;
}
}
Debug.Log(Target.Name.text);
return closetsPlayer;
}
@granite yew I can cook something up for you
yes plz
int FindClosestPlayer(int excludeIndex = -1)
{
float DistanceFromNearestPlayer = Mathf.Infinity;
int closetsPlayerIndex = 0;
Player[] allPlayers = GameObject.FindObjectsOfType<Player>();
for(int i = 0; i < allPlayers.Length; i++)
{
if(excludeIndex >= 0 && closestIndex)
continue;
if(i == localPlayer) //Fill in the index of the local player so you can skip it
continue;
float DistanceFromPlayer = (players[i].transform.position - this.transform.position).sqrMagnitude;
if (DistanceFromPlayer < DistanceFromNearestPlayer)
{
DistanceFromNearestPlayer = DistanceFromPlayer;
closetsPlayerIndex = i;
}
}
return closetsPlayerIndex;
}
Player FindSecondClosestPlayer()
{
int closestIndex = FindClosestPlayer();
int secondClosestIndex = FindClosestPlayer(closestIndex);
Player[] allPlayers = GameObject.FindObjectsOfType<Player>();
return allPlayers[secondClosestIndex];
}
I haven't tested but hopefully it works like intended and you understand what I tried to do
I can give a little explanation
First find the closest player, store its index. Then go through all players again but ignore the closest player index, which should give you the second closest
Yes you call FindSecondClosestPlayer and it'll give it to you
ok
You need to know who the closest is anyway to be able to tell who is the second closest
I made a mistake allow me to edit
using System.Linq;
//get 3 closest characters (to referencePos)
var nClosest = myTransforms.OrderBy(t=>(t.position - referencePos).sqrMagnitude)
.Take(3) //or use .FirstOrDefault(); if you need just one
.ToArray();
this will get the 3 closest
I've edited it but maybe napkins approach is better
ordered in closest, 2nd closest, 3rd closest iirc
@valid totem does it only work with all 3?
.Take(2) would get closest and second closest player
im not too well versed with Linq and OrderBy but this was a solution i used before
Seems reasonable to me and definitely a lot simpler and cleaner than what I did
uses n*log(n) time compelxity too so its great on preformance
I will try both @shut yarrow son can u give me ur new code?
I've edited the code so I would not spam too much here
I think napkins code works fine though, if possible use that
using System.Linq;
//get 3 closest characters (to referencePos)
var nClosest = myTransforms.OrderBy(t=>(t.position - referencePos).sqrMagnitude)
.Skip(1)
.FirstOrDefault();
This is probably a better way, and will return you only 1, being the second (i havent actually tried it but give it a go!)
@granite yew
this is completely different from Swansons solution
oh
so you would have myTransforms which would be an array list of transforms
would it be better with GameObjecgt[]?
You can use GameObject[] but in the code instead of doing t.position you would do t.transform.position
but then at that point you might as well change it to .OrderBy(g=>(g.transform.position - referencePos)
so the variables make sense ๐
but then I have to set the 2nd closets player to a GameObject reference called "Target"
I got 2 errors
error CS1003: Syntax error, ',' expected
error CS1026: ) expected
Can you show your code
I am trying Swason's solution now so I can see which one is better
If napkins solution works, definitely use his
Much less code so less chance of a bug and less clutter to look at
I can not guarantee I wrote bugfree code but I was hoping you at least could see the reasoning behind it
doesnt work lol
bruh
List<Transform> myTransforms
Yeah add all transforms except those of the local player since you don't want that one
Player FindClosestPlayer()
{
//get 3 closest characters (to referencePos)
var nClosest = myTransforms.OrderBy(t=>(t.position - referencePos).sqrMagnitude)
.Skip(1)
.FirstOrDefault();
}
@valid totem here is the code u gave me
Yes now use that and adapt it to your code!
also, this is not #archived-networking :P, should move to #๐ปโcode-beginner or #archived-code-general if you have more questions
Yes but its not networking related
I am just dumb lol
its just general game logic
so the which value in ur code can I set it as the Target GameObject?
hey, anyone here ever make a large scale MMO before? I got a successful kickstarter that reach goal + reach goal, and I ave a few hundred patreons.. my question is, on data management should i break my data up in as many tables as i realistically can or use larger master tables? for example, shipitems, playeritems, baseitems, or JUST an item table, atm I'm breaking the tabble down but, with 400 users (not even that many, I got a lot of my tables at like 14,000 rows and im wondering if i should break the tables down even more, and break this into TYPE tables, like, GameItemsSTORAGE, gameitemsInventory, gameitemshanger then, i can sib didive the tables again.
without deleting anything, just migrating what i already have
if you have a relational data structure it makes sense to normalize it to a reasonable degree (3rd/4th normal form) to avoid most consistency issues... so you should not create as many tables as possible but aim at eliminating redundancy. Counterbalance that with the query/join performance, caching complexity, transaction guarantees and realtime-ness of the data you need. With many concurrent realtime users it might make sense to only push valuable data (like a players inventory) into persistent database and keep unimportant stuff like current world position in volatile memory with a background worker shoveling acceptably recent state into persistent storage... i'd expect volatile data structure then to be potentially very different from persistent storage and not at all table-based
i have currrency transactions, run through thier own http terminal and table. I have 3 main DB that just share the same playfab ID, one is for the irl currency and premium status/expire dates, and then 2nd is for skills exclusively and their training times. mongoDB, and the 3rd db is for items using google and AWS Aurora. my logic behind this is I can remove dependencies and the more secure stuff can be written slower (i just wanna make sure it can get accidently deleted) so, the databases go with authentication/validation gates. obviously anything relating to irl money has the most, anything with skills(some take 90 days to train at max level) has the 2nd most, and then items and locations change the most frequently so, i just want fast write/load times. if that makes sense
i wanna reduce load times as much as i can
cause i think the standard is, 1 million rows is about 30 seconds
so, thing like currency only need a row per user but, some tables need to be made for currency convesrion using some of googles currency converters and build-in purchase stamping
those tables are hidden to me, but, they show up in bank statements
so, i dont care about seeing it now.
my primary question is about my 3rd/least secure DB
cause this will be updating and loading info on start up, and when the client DB attached to the network manger pings a new save on the server
and i want itteration to be fast.
you mean design iteration?
if i can get it fast enough, ill just use async on an invisible load scene. for saves
but, atm, i dont know what is faster loading on the 3rd database structure
atm, its like 10 secondsish
but again, its only 400 users
does the save data relate to anything or is it just a blob of data that gets read back into memory when a player joins?
load is structured.
it preloads all the assets related to the player at load
so, that way, when the player enters their space station
yes, but the data that drives it... does it have to be destructured outside that one load-process?
it can grab all the scriptable object under that locations id
i think i get what ur asking, as it loads, its matches values on a new object, instantiates that object on a list ob objets under that type
then in game load
yes
only looks at the lists that are relevent to itself
if you don't need structured data (strutured as in it has a schema that other processes will need to understand)... you can just MessagePack the whole thing into a byte[]
but that ofc prevents any kind of data migration (kinda)
i was looking at this,
Check out the Course: https://bit.ly/3i7lLtH
Ever wondered how to store large data for an RPG/MMO/etc? In this video, I'll go over a few of the techniques I've seen and dive into the one I see most commonly and why it works so well.
More Info: https://unity3d.college
Join the Group: http://unity3d.group
Patreon: https://patreon.com...
and he says dont use bytes
and gives some reasons why in his opinion its bad practice.
so, that why i build my client side this way.
watch it about a month ago
and was gonna go the binary route
but, hes like "no, if this happens at scale, or you wanna change a db value you gotta reload an entire patch
and its get super annoying for users
when you need to have a server downime and a new patch to download nearly everyday.
add me on discord and ill just tell you whether or not break my tables up increases or reduces loadtime on scale, (maybe when i get like 1k users+) etc
ill have a better idea if this was the right move.
yes, no data migration is a no-no... but for data with little value or cached stuff (i.e. not player items etc.) it can simplify things.
overall... the more structure your data has, the easier it will be to migrate things... A document store (like MongoDB), just from its design idea, is terrible (slow, complex) at querying structured data.
kk, good to know
Does anyone know how I can acces the player count of a session in fusion or how i can join a session ๐ค
Hi, working on getting smooth interpolation in my game, I saw the wiki and it said that the Boss Room example used two gameobjects, a visual, and a literal (colliders+logic), Do they seperate them into two distinct gameobjects? or is it a parent hierarchy? eg, PlayerLiteral>PlayerGFX, then the PlayerGFX would set its own position based on the smoothing? am I understanding it correctly?
https://docs-multiplayer.unity3d.com/docs/learn/clientside_interpolation/index.html#boss-room-example
Guide covering the basics of lag mitigation and a way to produce smooth gameplay.
Should it look like the first image or the second?
the problem is happening when i instantiate the player with Photon , thats why i am posting this here
i used animation rigging for my character
and then i animated the rig layer weights to make the player do stuff
but when i instantiate the player with Photon, the instantiated plyer dosn't change the rig layer weights when it should
can anyone help me fix this
please ping me if anyone responds
I would assume the first, because of in the CharacterVisualization.cs file, they are checking for a parent and destroying it if it has none.
oh, nevermind, after reading some more, it looks like the second one is right, and it just has a parent object assigned.
besides, if you have it transform parented, it can't "smooth the movement" towards the other object.
since it will just jump to the position of it's parent when it receives are server side position update.
but didnt what you just say, equate to it being the first option?
besides, if you have it transform parented, it can't "smooth the movement" towards the other object.
because this it cant be 2nd option?
No, they could be siblings though, but the ClientCharacterVisualization.cs would have a public gameobject parent; and you would assign that with the "server position object" and every frame lerp towards with with the GFX object.
I may have said it confusingly, sorry.
Basically if you have like
player ->
serverPositionObj
clientGfxObj
and the serverpositionobj is updated from the server, while the clientGFXobj every frame is lerping it towards the serverposition obj, it will smooth it.
That is very helpful
sure, or you could make the parent object a network object, but have the networkposition component on the "child" one
and the player object itself would just stay at 0,0,0 forever, I don't know if that would cause problems, but yeah
Just a little annoying that I would need to have two prefabs for each object lol
100%
(one literal one graphical)
Trying to figure out if there is a better way other than (it works but its not great) haha
The other option, that "may" work, is if instead, you grab the position on when the network updates it, and store it until the next position update, calculate the offset tothe previous GFX position and then lerp that offset to 0
I appreciate your input and will absolutely try it
which would allow you to have the obj structure like
player ->
clientGFXobj
and the clientGFXobj every frame is set (locally) to the lerped offset
though TBH, I dunno if that will work, and I don't know how hard it is to capture the network var update (I don't remember the specifics, but I think you can "observe" the changes somehow).
Yeah, np, hope it helps.
you'd of course have to do the same with with rot, but I think you get the general idea (basically what they do in boss room there, but changing it to update the GFX objs local position/rot to an offset that lerps to 0, so that it's always trying to match parent).
That actually helps me a bit, and maybe I'll build a small utility class that does that automatically, since that's one of the problems I had when I did some of the networking stuff lol, so thanks for making me think it through, weird how doing it for someone else seems easier to think through than when I'm deep in the code.
fusion is pretty new so youre better off asking the devs in photon discord directly
MIRROR 53.0.0 IS LIVE ON THE ASSET STORE
Download: https://assetstore.unity.com/packages/tools/network/mirror-129321
ChangeLog: https://mirror-networking.gitbook.io/docs/general/changelog
Hi, I making a 3D multiplayer exploration-survival game and I want to be able to save world data( where players built their houses, and all that stuff) Here is what I'm thinking: a player creates a game and the world is being downloaded on their pc. When a player connects he gets that data. If a player is building a house the other players will see him placing all the house parts. Is there any way I can make that for free(using photon networking)
Hi, there actually 3 different parts to your question:
- what netcode to use (for free). From photon, I'd suggest Fusion, as it is the right solution for a more complex survival game. And just like PUN, you can have 20ccu free for development. You could also use MLAPI or Mirror, but to actually have the player communicating without running (paid) dedicated servers, you need to look for a punch-through solution (that to be complete needs a relay fallback - not sure if there are free ones). Maybe adapters using Steam network do this.
- for persisting the game state between sessions, this is your job... you need to serialize your game state, and develop a way to re-initialize it... Not really something you will get off-the-shelf.
- And, to STORE this somewhere (for free) you will either just store locally on the player's machine (so he could restart his server - like Valheim players do)... If you want to store online, I don't know free services for this (that are actually appropriate).
What about integration with MySQL?
I don't use Photon but my guess would be that it doesn't know how to serialize a Vector3 by default. You'll have the same issue with the Quaternion I think.
I would check the docs to see if you can provide a custom serializer for any class. In last resort I would send each component of the vector separately
It was working before, but now its not
I was following this tutorial for this
I see, looks like you can yeah
It's also how they instruct to do on the official doc https://doc.photonengine.com/en-us/pun/v2/gameplay/lagcompensation
Photon Unity Networking framework for realtime multiplayer games and applications with no punchthrough issues. Export to all Unity supported platforms, no matter what Unity license you have!
Not sure why you would receive an int instead of Vector3 ๐คทโโ๏ธ
how can one do a certain action if client's attempt to connect is outgoing? (mlapi)
as in, if you try to connect continuously with no success, just stop the search for hosts
try statement doesn't work since there are no errors
private GameSoundScript soundScript;
private Vector3 currentPos;
private Text debugText;
public override void OnStartClient{
base.OnStartClient();
if(!hasAuthority) return;
soundScript = GameObject.Find("Game Sound").GetComponent<GameSoundScript>();
debugText = GameObject.Find("Debug Text").GetComponent<Text>();
}
void Update (){
if(!hasAuthority) return;
currentPos = transform.position;
if(!soundScript.soundIsPlaying){
foreach(var item in soundScript.DictionaryTest){
debugText.text = "Player pos: " + currentPos;
}
}
}
I am using Mirror. When I set the text in the if clause, it works normally but when I set the text in the foreach loop, the text appears only on the Host screen, not the Client screen.
Can someone help me please?
It seems to me that you're checking if its the server with !hasAuthority
So, if its not the server, dont do any of the code below
If I remember correctly from my short time with Mirror, that is how it works
With Photon can i create a room as soon as the client joins the lobby?
Okay I will try to remove them
does anyone know?
because i cant get it to work.
Your question is quite broad, but yea im pretty sure u can do that
Never worked with Photon but that seems pretty basic
What are you trying to do?
What you pasted is literally short-circuiting itself on non-server/non-host/non-authority things
Which means of course it won't display.
Hey guys little qeustion i made a multiplayer game via Photon
But i want now to try it via server based that i cna host on my own so any good tips for tutorials
Or a better networking sollutions?
Use Photon Fusion instead of PUN
There's a few free ones, and of course, paid ones like Fusion. Take a look at each one before considering which one to program with.
Fusion is a good paid choice. Free ones include Mirror, Unity's own stuff, MLAPI, etc.
Just do your own research and dabble around with each candidate before you settle
Is their one for example my player makes a world on his own pc and poeple can join it is their a way to do that?
he sort of host his own server
i mean like minecraft survivial for example
and poeple can join you from your pc
becaus i know this is how scrap mechanic does it but how
LIke i make a survival world and other poeple from other wifi can join me but its not running on a server
Of course
Mirror can do that, MLAPI, etc
For example, you'd start host mode, then you give your friend an IP address and port, they punch that in and off you go
so pretty much every sollution can do that?
Implementation varies but yeah, most (I say most, not all), support client hosted games
Where one client is godmode over everything and the rest are just normal clients
but in scrap mechanic you just invite your friends over steam and without an ip is this also possible?
Yes, you can do that
Often this is called a listen server / client host. Most networking solutions will support this but getting clients to connect to each other will need some effort in the form of using a relay server or port forwarding. https://docs-multiplayer.unity3d.com/docs/learn/listen-server-host-architecture
Mirror for example has the Steam transport which harnesses Steamworks
Tutorial for what?
If you don't want to do port forwarding, you could for example, use again Mirror but with a relay for example
to do make that system
If you want your own minecraft-like stuff, I'd probably point you to uVOXL which I believe is made in the style of Minecraft
Well, if you're completely green to networking, I'd suggest making your game work as a single player prototype first
oke
then integrate multiplayer in later prototypes
Reason I say this is because some ideas and whatnot may encounter problems being networked
i made an fps with photon so i am not completly new to multiplayer
Sure, but making a minecraft clone is completely different than a shooter
yea
Using MLAPI. Anyone have a good tutorial on getting this set up?
"Host your game locally and open ports in your router. It should work just like over LAN you just have to connect to the public IP itself. Make sure to open UDP on the router."
For the "host your game", use literally any tutorial or, better, the docs, for the "open the ports" well there's not a general procedure, every router has a different way to do that
guys how does MLAPI handle spawning objects in a very different location with many players? Like in a survival or open world, where two players far apart have different objects spawned, and only the server has to handle all the objects simultaneously, while every client spawns only the nearby objects
@indigo thicket I've done pretty much everything in my open world game for multiplayer except enemies. But I figure I just use .spawn() when players get close and .despawn() when no player is nearby.
I'd host locally and test with 2 devices (or 2 builds on 1 device). So your main device would be (for example) 192.168.1.10 and second device would be 192.168.1.11
Opening up ports without knowing much about networking is asking to get hacked
oh, 2nd device has a different ip address? thought they all have the same using the same router, ok
I also read I can do a relay with Steam since its a Steam game. So maybe I'll just wait to do it this way. Opening up ports sounds dangerous.
The router hands out IP addresses to all devices on it's network. So your phone has a different one that your PC. If you got a game running on 2 devices on the same network with MLAPI running on both, you can get a local game running on both devices
Yeah relay would be a better alternative for multiplayer through the web, even if it's slower. Eventually you'll learn about networking and servers and stuff and might get the itch to build out a server to host games for your friends that's super performant. But you'll also need great internet
its not a FPS so slower is fine.
Hey all, does anyone know why only the last joined player is the local player (IsLocalPlayer)?
Im using MLAPI
And im checking for IsLocalPlayer in the update of a NetworkBehaviour script
when i join with multiple players, only 1 person (localplayer) can actually get in the if check.
Frog is the actual movement handler, its another script on the same object. ill send some screenshots
also the object the scripts are on have networkobject, networktransform and networkanimator
Can there only be 1 local player on one machine?
@wind citrusHey, the Rpc is called on the next update so if you are sending inputField.text in the Rpc then right after change to "" it will just send "" because Rpc is done after the update.
the thing is, it doesnt even send. when i press enter to send, it simply does nothing
ok
ive debugged it and it never gets to the input check
I haven't used isLocalPlayer at all.
I always use isOwner in all my multiplayer stuff
So maybe this might help, for each player what I did was activate only the player that is yours with a bool as true. So I didn't have to use isLocalPlayer.
i just tried it with isowner but what it does is (same as localplayer), when i host my game and join myself with a build client only the client can talk (hes the localplayer) then if i join on a 3rd client, that 3rd client is the localplayer
And this is prob bad but it works. I search for all players and the newest player is always the last one found so I just activate that one as yours. Because new objects in hierarchy is placed at the bot so it finds it last in the search.
how did you "activate" it?
Well, this would spawn every object for everyone. If a player is in a completely different location he spawns the objects/enemies too. This could make everyone lag, because clients are not always powerful, while servers should...
@indigo thicket damn this is tough. cause my next thought was to check the distance of other players, if its just you then don't .spawn() it, just instantiate it in as normal. but then if there is 2 players there and 2 players elsewhere then all players get it. idk man ><
if I instantiate as normal, the server can't process it :\
well yea, thats the point if your the only person nearby
Well the server should be the one to handle something like spawning objects, getting them or handling enemies, for very basic cheat control
not really important in my game
but still weird to let the client simulate everything, perhaps it's also a problem if a player get close to another and has to spawn the local objects
the other thought and idk if this works. can you disable on the client side, the networkAnim and networkTrans?
so your not sending info over everytime?
I thought that too, but idk
I could create a custom function that spawns an obejct only for some clients, and the other clients "despawn" it
if it works
I have done everything but the enemies in my open world game. so this is good to think about. cuz i have to do the same thing ><
btw, have you sent big moles of data to a client? Like tiles of a map
you wont be able to send much data at the same time with 1 rpc
you have to break it up into pieces
ok
the rpc is blocking/has a maximum bytes?
so i can help u with this
you are not gonna want every block 20x20 to be a networkobj, this is bad.
you are gonna want each player to hold this data by itself
ok
this is like MC, you move and it generates the world in chunks and you need other players to see this too?
I've already encountered some problems sending custom classes via rpc, even serializable ones, but I think I was doing some mistakes since it was the first time using rpcs
yeah, but 2d, so with way less "blocks"
just a 20x20 matrix
of integers
tbh, you can prob make an algorithm so you don't have to send the info over. Like my huge open world is generated with 1 map seed and so i only give the map seed to my clients.
plus some objects like rocks, walls etc (that's why I asked how could I spawn things only for some clients)
you have a random algorithm for new chunks?
Well yeah right now it just uses random
cuz if its not random, u wont have to send much info, just where the chunk needs to go
I could throw a seed and get the same random every time
this would block every tile-editing by the player, but i'm not currently planning to add it anyway so that's not a problem for now
i keep an array of all my objects that are removed. and all build objects. with an objectID. well the build objects I need more info to send, like pos and rot.
so your talking about tile-editing should be fine
Ok, thanks
hope the local spawn will work
and I'll definitely use a seed now
ty
yw
@indigo thicket hey I was thinking about the enemies. I think what Valheim did was the enemies do .Spawn() but with networktransform and networkanimator turned off. Like I remember seeing the enemies far away in that game as statues. then when you moved in closer they started to animate and patrol.
Hey guys, I'm using Mirror Networking (similar to the old UNET framework). I'm trying to set up an FPS such that I have a server build running on a Microsoft EC2 instance and a WebGL client running on a Squarespace website with an insecure SSL certificate.
So far, I can connect to the server build when running the WebGL build locally, but when I try to connect from my website, I get "websockets failed to create secure connection".
I'm still in the middle of fiddling around & testing with the "ssl enabled" and "client uses wss" flags but what does this error mean and what is the correct way to set this up?
When instantiating a player using Photon
Is it possible to just Instantiate a gameobject from the hierarchy instead of instantiating a prefab from the project files?
Please ping me when anyone responds
Why would you want to do that though
i have a Player controller, it holds the weapon
and i used animation rigging for it.
the animation rigging works perfect
but if i make the player into a prefab then the animation rigging no longer works
and it dosent work even after i unpack the prefab
Maybe you can just normal instantiate it so that you can reference and object from the scene but rpc the instantiation over the network?
I'm having two problems with mlapi, if I add the approval check to my script handling connections the approval check is not ran even when assigned to the event. It appears this needs to be in a different script to run, I decided to attempt to code something much simpler and smaller than running off the server/client/shared scripts from boss room, so this is just going in a single script handling the StartHost() and StartClient() connections.
Secondly, when I connect as a host I will spawn the player object and be able to connect to server and run around, however when I switch scenes on a client (not host) I get an error scene switch can only be done by the server. I did have it where both players were running around in game on the server. however when trying to add new things it was getting broken and trying to deleting the player prefab of the client. Also, if I scene switch without mlapi and use unities normal scene manager it doesnt work properly. The client wont stay connected if I do a normal scene switch.
I notice the approval check is in the server part of the code, however there is no serverrpcs in that code in the boss room, what I was saying above is this is just using a script to handle the connections, and I'm not sure how those scripts without serverrpcs are all considered to run on the server
how?
just find the object in the scene you want to instantiate
the to normal instantiaition as such : Instantiate(gamobject, transform you want to instantiate it at); but put that in an rpc function to all other clients so it instantiates for all of them over the network ๐
but wont we have to do it like PhotonNetwork.Instantiate to make it register as the player's?
no if it is in an rpc it will happen over the network
So every player will do it on themselves
ultimately meaning the same as PhotonNetwork.Instantiate
Hey guys , Iโm using fusion and I am really confused how to join a session it should seem simple and lots of people seem to be able to make games with it but I can find anything ๐
I think you are also on the Photon Engine Discord. Probably better to ask there and specify what the problem is...
Our latest version 1.0.0-pre is currently in pre-release and will be fully validated for production when the next LTS releases (next year). https://forum.unity.com/threads/release-announcements.1105324/
Does anyone know why only the last player that joins is seen as the localplayer? I've been looking for hours but i cant find out why..
this is what my networkmanager looks like
I'm not sure what you mean by only the last player being seen as the localplayer.
Ok so when i host my game, the host is seen as the localplayer. Then when i join with another player, the new players IsLocalPlayer value is true and the old player's value is false
basically only the last player that joins reaches the actual Input.GetKeyDown check
I'm gonna test that! I didn't know that valheim use mlapi
so on the player object owned by the host IsLocalPlayer becomes false as soon as you connect another player?
but whats weird is that in the movement script, i can walk on all players..
yeah, but it also happens when theres for example 3 players and a fourth joins
then the fourth is the only localplayer
Yes that is to be expected. LocalPlayer means Player object which my specific client owns
yes thats what i thought aswell so i tested it with 2 other people (different pcs) and we joined. But still only the last player that joined could talk
Are you sure that this is not related to your chat implementation. If movement works the IsLocalPlayer property should be working correctly.
ok so when i host the game andi m the only player this is the localPlayer value of the host. (Debug.log in movement script):
now when i join on a build:
Yes this is to be expected
But they can both still walk which is really confusing me..
On the host once you join there are now 2 player objects
- The player owned by the host where IsLocalPlayer is true on the host
- The player owned by the client where IsLocalPlayer is false on the host
yeah and for the build its the other way around right
for the client
there the client is the localplayer and the host is not
But then its so much more confusing since in my chatting script i cant get past the first if check on the host now
Both scripts inherit from NetworkBehaviour and are on the same object which has NetworkObject, NetworkTransform and NetworkAnimator
Try adding a debug log to see if that's really what's happening?
Hmm i added a debug log in the movement script which debugs the animator controller (This is so i can see which log belongs to who). but thats giving me a nullreference for the client
even though its not null on the client
the IsLocalPlayer did stay true on the host.. but he still cant chat
Hmm ok you were right, when I join on a client, the host is still the localplayer
but then its really unclear to my why it doesnt get to the input check..
wait ... it does detect my input still
it just doesnt send
It doesnt get past the inputField.text.Length > 0 check
Okay i found the problem...
The Inputfield i use to write text in doesnt update when theres a client in the server
its always 0 and doesnt read the value i wrote in
I'm trying to understand network stuff and Using MLAPI and read this line on the page 'The library cannot track objects that start in the scene.'
I want my scene to be designer friendly for when I do level design but some of the objects in the scene need to be able to move. Does this mean I have to rearrange and find a way to instantiate these scene objects?
Where did you read that?
@verbal lodge on the Unity MLAPI documentation/tuitorial https://docs-multiplayer.unity3d.com/docs/tutorials/helloworld/helloworldintro
Tutorial that explains creating a project, installing the Netcode for GameObjects package, and creating the basic components for your first networked game.
This is not true
Just the player object is handled differently, but you can have scene objects.
so you can still have scene objects move without spawning them in a special way?
Yes just put a NetworkObject + NetworkTransform on them, have them move on the server and they will be replicated.
Thankyou ๐
I think I might be better waiting a while I get a bug when trying to follow the tuitorial. it dosn't seem to like
using Unity.Netcode.Messaging;
using Unity.Netcode.NetworkVariable;
The type or namespace name 'NetworkVariableVector3' could not be found
Can you give me a link to the page you are using?
Tutorial that explains adding scripts to objects, editor modes (Host Server and Client), basic player movement,Permissions and basic RPC use.
On my machine it shows updated for instance public NetworkVariable<Vector3> Position = new NetworkVariable<Vector3>();
Try ctrl + f5
cool it's updated now. Thanks
If you run into any other issues let me know. We just recently updated all our docs so it could very well be that a few things are still a bit shaky.
so i need to get the result.Data[Key].Value.ToString(); to be returned to the function thats calling it i have this but it dont work: ```public string Get(string Key)
{
var Requst = new GetUserDataRequest { };
PlayFabClientAPI.GetUserData(Requst, result =>
{
return result.Data[Key].Value.ToString();
}, error =>
{
Debug.Log(error.ErrorMessage);
});
}```
i was asked to put it here not in #archived-code-general
How do I make it so a function calls only if ur name is equal to a specific text in photon unity networking?
what do you actually want to do tho
I already solved it lol
oki
How can I enter these -d parameters when I create a UnityWebRequest?
It didnโt work when I input it as a string
UnityWebRequest uwr = UnityWebRequest.Get(url);
Here is the other example, I donโt know how to do either.
The first looks easier, I just need to be able to enter my authkey and target language as well as my string I want to translate
Everything you need for a language translation in one place. Easily integrate directly into your own products and platforms.
It does not seem to be a data object that you need to create, so you basically just add the variables to your url;
"string myAuthKeyVariable = "abc123"; string text = "Hello,world"; string targetLang = "DE"; using (UnityWebRequest www = UnityWebRequest.Post($"https://api.deepl.com/v2/translate?auth_key={myAuthKeyVariable}&text={text}&target_lang={targetLang}")){ // handle coroutine } "
And here's how to create a post request with Unity
I have a question: Im working on a project with multiple Player (using Mirror)
I want certain things be to the local player invisible like hats, nametag (...)
How can i make certain objects invisible to the local player?
If i look up, i see my own nametag for example
@molten condor every network behavior class you inherit from allows you to access isLocalPlayer bool
yes. but i dont know how to make it invisible to local player
im sure its not if local player
object.invisible
if(isLocalPlayer) yourGameObject.SetActive(false)
if (isLocalPlayer)
yourGameObject.SetActive(false)```
?
is this right?
so
If my game object is called BOX
i have to write BOX.SetActive (...)
and put the Script on the Game Object?
or have i to put the script on the player?
You can put it wherever you want as long as you can check if you're the local player and if you have a reference to the object you want to disable
ok ill try
Ive set a reference now .
Is this correct to use the reference?
cause in this reference there is a .gameObject. between the object and setactive
Because camera is a component, and every component in unity has a reference to the gameObject its on. But if you're already accessing the gameobject directly you don't need to put it
ok thank you
so a canvas / text object isnt a component?
well the text is attached to the canvas and the canvas is attached to the player. so i have to write nameTag.GameObjective.SetActive(false);
right?
you mean its a child of the canvas?
