Hi Everybody!
Recently I am experimenting with various networking solutions for the project I am developing. Although I found a possible way to go with Photon, I wanted to explore the features offered by the Google Cloud Platform service for a Real-Time Multiplayer application.
After a search, however, I managed to find only articles and podcasts that mention a collaboration between Google and Unity, without finding actual documentation, tutorials or applications.
Do you know if it exists and where can I find this material?
Actually, I’m thinking on something different, like firebase, or even better, a Google virtual machine, but I don’t know if it can ensure a data transmission sufficiently fast for a, for example, 6v6 fps or moba.
I would like to try it but I would appreciate some introductive docs first ^^
Firebase is an app building framework, a Google virtual machine is just “hardware with an OS” that you can use to run applications. Apples and oranges. Also Photon is yet another kind of “fruit”.
I think you should clarify what exactly you’re trying to do.
You are right, I have not been very clear. I try to explain what I’m going to try when I have some time (probably this weekend …).
I would like to create two different builds of my project, one that works as a server and one that works as a client, so that they follow this pipeline:
The client collects the player’s inputs and sends them to the server.
The server processes them, moving prefab, spawning GameObject, checking for collisions, using NavMesh, even saving some permanent datas using PlayerPref.
These objects are then synchronized on the client which shows them on the screen.
What I would like to do is create two different builds, removing everything related to interactions and events from the client code, and all the graphics part from the server.
So put the server on a Google VM (which being linux based should allow me a headless build) and see what happens.
I was thinking of using Unet as a networking system, although deprecated, but I don’t know if it allows me to create two asymmetric server and client applications.
Ok now it’s clear and it seems perfectly doable. I’d expect the server part to be able to handle a 6v6 FPS on a single Google VM.
As regards the two builds, I am not sure how much stuff can be stripped off of the two executables. In theory they need most of the assets in order to either apply the server logic or just render them on client. Maybe you could use conditional compilation to exclude code that is not needed on one side? I am not sure, though.
Yes, I was thinking of starting by separating the two situations with conditions, something like “if (isServer) {…} else {…}”, and then maybe cleaning up the code if I get results. As for assets, I wanted to see if I can use different prefabs, for example a simple cube for the server and a more complex geometry for the client.
Ok, let me give you some updates:
I prepared the project, using Mirror as Networking system because it is similar to Unet and, in my opinion, suitable for my purposes.
Using if (isServer) {}, if (isClient) {}, if (isLocalPlayer) {} and obviously [Server], [Client] and [Command] I have outlined the two cases, server and client.
Finally, to actually create two different builds, I used the build symbols (#define#if#endif) to exclude all code delegated to the server from the client. (in this link it’s explained how to set the symbols for the whole project).
I will give you an example (this is not actual game code)::
[ClientCallback]
private void ManageInput()
{
if (isLocalPlayer)
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
CmdShootRocket(ray);
}
}
}
[Command]
private void CmdShootRocket(Ray ray)
{
#if SERVER
if (cooldown <= 0 & Physics.Raycast(ray, out hit, Mathf.Infinity))
{
Vector3 direction = hit.point - transform.position;
direction.y = 0;
SpawnRocket(direction.normalized);
}
#endif
}
#if SERVER
[Server]
private void SpawnRocket(Vector3 direction)
{
GameObject rocketClone = Instantiate(rocket, transform.position, transform.rotation);
RocketControls rocketControls = rocketClone.GetComponent<RocketControls>();
rocketControls.Direction = direction;
NetworkServer.Spawn(rocketClone);
cooldown = 3;
}
#endif
As you can see in the client build you can exclude all the content from the [Command] functions, because is processed on the server.
Now I fix two more things and then I try to put the server on a Google VM.
Ok, I put the server on the VM and I have to say that everything works perfectly.
But I need your help again. Since on the server is a headless build, I need to show any log messages directly on the console.
I was unable to find a direct solution, but only workarounds that involve creating a log file using the -logfile command and then printing changes to the file on the console.
For some reason, however, my build does not generate the Player.log file. I have trie dto change the writing permission in the directory and even change the destination path, but nothing.
I think it’s probably best to use log files and if you want to see their content live you can “tail -f” the log file. At least on Linux and Mac. On Windows I believe there’s something equivalent via the power shell.
You could also try using Console.Writeln() but maybe Unity redirects that output away from the standard output, I don’t think I’ve ever tried it.
Yes, Console.WriteLine() is also redirect.
I have tried various solutions for this problem, and all of them involve the use of the -logfile command.
After several attempts I found two solutions: use -logfile -, which, in theory, should send log messages directly to the console, or -logfile server.log, which generates the log file which, as you say, can be sent to the console via the tail -f command.
The problem is that in the log file there is no trace of the Debug.Logs launched by the server, but only the normal report generated by unity and by the networking system (Mirror).
Not for now, since I don’t need to pass -batchmode and -nographic (the build is already set headless when i compile it). Now I’m at work, as soon as I can I try to add more Debug.Log, maybe one every few seconds, and i watch what happens.
What’s weird is that I think I’ve already done something similar sometime ago, and it worked. It was something I did for a client, but it doesn’t come to mind right now. I’ll see if can refresh my (faulty) memory.
Guys, i’m very sorry
I’ve tried to cast a Debug.Log every 4 seconds inside a GO and it actually works. I don’t know what is changed, but now it works.
For the ones that want to know how to do that, you just need to launch the program with the command -logfile -, E.G.: