mercredi 28 décembre 2016

Dedicated Server packaging

Dedicated server packaging


I found that Url in the wiki : https://wiki.unrealengine.com/Dedicated_Server_Guide_(Windows_%26_Linux)

But I don't know it is outdated, or I have particular case, but following this, didn't success for me.
So I will give you my way to do, and few tricks, because some configuration steps are necessary and there is no place aggregating those informations.

In my game, I will have one server per map, because each map must be persistent, and is not upon a player.
So I have to generate one server per map.

Tricks & Settings


If you have already launched your game through commandLine like "ue4editor projectName mapName -server/-game", it is quite simple, because you give in parameters the name of your map.
So in your test, you can go map/through map just changing your command line parameters.

When you generate/package your game, it will fix these setting once per package.
First step, you will have to configure under the editor the maps & modes settings.
In these window, you precise which map the client will start with, and which map the server will start with.


Another trick is about package non ue4 files. I manage some configurations files, or data files (json files) in my game to store dialogs, missions, ..., and these files are open by C++ code.
So Ue4editor didn't consider them like assets. In consequence, when you package your game, those directory, and files are not packaging. so bad....
So go to your settings, packaging settings, I recommand to uncheck use pak file in a first time, because you will be happy to see the package content in the first time to validate its content.

Go down, to to Additionnal non assets directories to package, and browse to your directory to add it to your package.


You can refer to the wiki for other steps until unreal front cooking. I don't use unreal Front to package & prepare my game.
I use Ue4editor, through file->package project.

Packaged


At the end of the processus, you will have a directory "game" with WindowNoEditor, with two directories Engine, and yourGame.
Go through yourGame/Binaries/<platform>/ you must find a yourgame.exe, and yourgameserver.exe.
If you don't have your executable, maybe you forget to generate with visual studio (see the step in the wiki).
In certain case, you have to copy the binaries yourself, from your building directory, to your game package.

That's it. I recommand to through a shell script, or command line to launch with "-log" parameters to check that your server & games runs without problem.

I hope it will help people who want to manage dedicated server.

Thyshimrod

mercredi 15 juin 2016

Unity : networking part II

I create a tiny connection screen in a nex scene. This scene has no network, only a canvas to show a background picture, and panel/buttons.
To be exhaustive, I ve created a gameobject named PLayerOverScene I talked about in previous article. I linked to this gameobject, the playerscript script. I will store in it, some information, like the ip asked by the player.


Important field for me, now is IP and connect.
I will not speak about login and password for the moment. I will use a rest repository, I will connect to, to validate user/password in a further article.

As always, I will create a c# script to handle click button on connect : ShimConnection.
I create a single simple function:

 public void checkLogin()

I added the script as component to the button.
I create a onclick event on buttonscript component.


For now, when you click on connect button, you will call checkLogin function.

Travel

Now what you want is to load the game scene, and to link to the networked scene from server.

At connect click, I store the Ip into PlayerOverScene:

GameObject playerOverScene = GameObject.Find("PlayerOverScene");
PlayerScript plScript = playerOverScene.GetComponent<PlayerScript>();
plScript.setIpToGo(IP.text);

First of all, you have to load the new scene (I have only two scenes, so for the moment, I will put hardcoded name of the scene).

     SceneManager.LoadScene("scenes/level1");

The game scene will be loaded... now we have to connect to server.
I Will modify this previous code :
public void Start()
    {
         GameObject playerOverScene = GameObject.Find("PlayerOverScene");
        if (playerOverScene == null)
        {
            bool result =this.StartServer();
        }else
        {
            this.StartClient();
        }   
}

To


public void Start()
    {
         GameObject playerOverScene = GameObject.Find("PlayerOverScene");
        if (playerOverScene == null)
        {
            bool result =this.StartServer();
        }else
        {
           PlayerScript ps = playerOverScene.GetComponent<PlayerScript>();
            if (ps)
            {
                this.networkAddress = ps.getIpToGo();

            }
            this.StartClient();
        }   
}

I grab back the Ip store into playerOverScene object to determine to modify internal variable (networkAdress).
I start client, I am connected (I hope) to the server.

Quite simple...


Next step, I will describe how to spawn the player ship...

jeudi 9 juin 2016

Unity : networking part 1

In the way, to have a dedicated server, and client able to connect to it, you can use standard script from unity. One of them, draw a little hud, where you can choose to launch standalone server, a client, or client hosting server.

Another script is more usefull and manage all events upon network : NetworkManager.

For my purpose, I create my onw c# script, inheriting of networkmanager. I wish to override several events, and function, so it is the best way to do. Its name will be ShimNetworkManager.

As in any script, you have a start and update function. In the start function, I will start a server, or start a client.

When the scene will start, this script must be runned. For this, I will add in my scene, a simple GameObject. I will name it NetworkManager.
I will add as component, my newly ShimNetworkManager script.

For now, as you will launch the game, it will execute automatically this script. But how to know if I am a server, or a client?

From my mind, it will be a server, if the game is loading directly this scene.
If the load of the scene comes from an another scene, it is a player trying to connect to a client. It is my assumption.

Pass GameObject scene to scene


I spent lot of time on this question.
When you load a scene, you destroy the old one, and all object belonging to this scene, even those you have instantiated by a script.
Finally, I discover a trick that allow to pass scene to scene some GameObject. So, to know if this is a client that is loading the scene, I test the existence of this object.

I create a second scene, named authentificationLevel. In this scene, I create a GameObject named PlayerOverScene.
I create a c# script named playerScript which will contain in further articles, the information linked to user (name, id, ....).

To allow to an object to be not destroyed, when you change your scene, you have to code this :

void Awake()
    {
        DontDestroyOnLoad(transform.gameObject);
    }

This line of code save your life.

For now, in all scene you will go, this object will remain, and you have a good way to store game information (score, player information, server information,....).

Back to Networking : Client or Server

In ShimNetworkManager, I can test this PLayerOverScene Object to know if I have to run server or client.
public void Start()
    {
         GameObject playerOverScene = GameObject.Find("PlayerOverScene");
        if (playerOverScene == null)
        {
            bool result =this.StartServer();
        }else
        {
            this.StartClient();
        }   
}








mercredi 8 juin 2016

Unity : Shimstar ; reloaded

OK let's try to create a multiplayer space game with 6 degrees of freedom.

I am not sure to follow the right way to create a game from scratch, I will write articles depending of what I consider to be important to know to create a multiplayer game, with physics.

SkyBox


Because, I like to be in the atmosfear, I ve created a skybox using SpaceScape to grab 6 textures.

I create into a folder, named Materials a new Material called skybox. In the inspector, choose the shader (skybox/6 sided)


Next try to add your 6 images to have in the preview your skybox.

Now you can go to the top menu "Window", and choose lighting, to make your new material effective to your scene :

Modify light configuration, to have an ambient light to light your object into the scene.


Networking in Unity

A game is at first defines by different scene. A player will play into one scene, and can travel scene to another scene.
In a configuration of one server, and multiple client connected, you will have a server running for each scene you will create.
The client will loadLevel and connect to the server it needs.
Server must have authority on physics, and will receive input from client, and broadcast results to all client who needs it.
You don't have a global server which manage a world with subscene. It is important to understand this.
Indeed, you will to manage to connect to a scene, and to disconnect from the scene, to connect to another scene running elsewhere (different IP, or different port).

In Unity, each object of the scene, can have multiple component:
  • mesh
  • material
  • scripts
You can associate as much of script you need, to manage behaviour of the object.
For example, you will have 3 scripts:
  • network identity : standard unity script which provide an unique network identity
  • network transform : standard unity script which manage the data transfer of position and rotation of the object
  • your behaviour script : custom script, with your specific fields, and function to manage custom behaviour
Unity will manage network behaviour on object possessing networking script.

Next Step


I will try to describe enough in details the different mechanism, during construction of the game.

I will show you how to manage a connection scene, and connect to a server.

After that, I will show you how to manage physics through networking.







mardi 26 avril 2016

ShimStar : Poc Unity

I made a poc with ue4, and it appears that, from my mind, ue4 is a great tool.
But it is heavy... and for my purpose, I wonder if it is not something to huge to use, for such a game I am doing.
The editor runs down my laptop, compilation time from C++ is very long, and there is a huge orientation to character use, and fps.
But the community is very good, and it was a pleasure to work with such people.

I am trying for weeks unity, and my first opinion is it less matur, not totally finished, UI is not so good, and community is not very good. I think there are lot of amateur, and it is hard to have good answer, and when I ask about technical stuff it is quiet hard to have answer.
But unity is liter, but powerfull... and for the moment, I can reproduce lot of thing from ue4 in unity, and an easier way.

I think you have to program more, but it is c# so more convenient, and faster to compile and to test.

For the moment, I am trying, and see what I can do, and I will try to find the limit... but I am quite happy of unity.

I repeat, UE4 is wonderfull... just too much heavy for me:p

jeudi 18 février 2016

ue4 : AI in a space game : relative coordinate : part 1

I will make some articles about AI I am building.
I will not use for the moment, tooling set in ue, because I will not have change of behaviour (attack, defense, patrol).
I will for the moment make only one behaviour, and one goal to reach, without modification depending of the situation of the AI.

My goal is to put in space 2 cubes, and to spawn an AI pawn controlled by an AI controller.
The AI will retrieve first cube, and will fly to this one. It will shoot at it, destroy it, next it will change of target, and fire on the second one.

I ve created a pawn, with a static mesh, with physic enabled.
Don't forget to precise that the pawn is possessed by your specific AIController blueprint:





For my purpose, one of the central need I have, it to be able to orient my pawn to my target.

In AIController,  I ve defined a variable TargetToGo
and create a function to associate a value to the target


I retrieve all object in the scene which are from class gopoint (my cubes, there are two of them). If actual targetToGo is different of the one retrieve in foreach loop, I affect it, and break the loop.
Quite simple.

Ok, for now, I have a target for my pawn... The difficulty is to know how to orient my ship to the target, to move near it, and shoot at it.

Ue4 gives possibilities through transformation tools, to make world location, in local location relative to the ship.

From my pawn, and target, I retrieve static mesh.
From AI ship, I create a transform object (world transform) and I connect it to an inverse transform location object. This last one is the way to make world location into relative location (transform location does the inverse, relative to world).
In parameter, you give actual world location of the target, and you will have a vector in output.




Now, if you break the vector, y which is a left/right coordinate, and z a up/down coordinate. When z and y are at 0, target must be in front of you.
X value in case of y and z at 0 will be the distance to the target.
X can give you clue, if your spaceship is going to, or going away of. If x is equal to - (distance), you are going away from the target.

You have to make rotation, to make x near from distance, and then re apply torque to reduce y and z to 0





dimanche 14 février 2016

Third Party server with UE4 : part 4 : C++ : thread

UE brings you what you need to thread your program.

class POCSHIM_API UShimServer : public FRunnable

just extend the interface FRunnable, you will have to implement
    virtual bool Init();
    virtual uint32 Run();
    virtual void Stop();

Run will be the function which will be threaded, so you can put a while (1), with a break condition, mutex, and so on into.

I ve created a singleton in shimserver

in shimserver.h:
static UShimServer* getInstance();

static UShimServer *instance;


in shimserver.cpp
UShimServer*  UShimServer::getInstance() {
    if (!UShimServer::instance) {
        UShimServer::instance = new UShimServer();
    }
    return UShimServer::instance;
}

UShimServer* UShimServer::instance = nullptr;


In myGameInstance class, I ve created an intialize function, which retrieve the singleton of shimserver, and from it create and launch the thread.
once you create the thread, it will run automatically init on instance, and run().

Third Party server with UE4 : part 3 : C++ : connect and read socket

I ve created mainly two functions, one to connect, one other to read socket


I think it is quite easy to understand, and easy to modify to what you need, because apart port and ip, you don't have to modify lot of thing :D.

this->connected, is a variable to store connection status, you can use in a function like isConnected :D


This function will read the socket, retrieve the data in receivedData.
In my case, I will deserialize data from string to json, and I will store the message into a customize class, which will store all message.

This function is called each tick, because I have not lot of information send into these socket.
If you prefer to thread it, you can





Third Party server with UE4 : part 2 : C++ : include package

For now, we need C++ code.
I will not explain how ue manage class, path to includes, and so on. All is not very clear for me.
It seems that when you need to use "package", you have to include it in your build.cs.

Here it is a screenshot of filetree on my computer, of the engine source. In red the non exhaustive list of package under source/runtime.

We will need socket package, and networking, so in my build.cs

using UnrealBuildTool;

public class pocshim : ModuleRules
{
    public pocshim(TargetInfo Target)
    {
        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore","Blu", "Networking", "Sockets","Json" });

    }
}






Third Party server with UE4 : part 1 : nodejs

I have discovered that ue4 is very good for certain purpose, but not good for others.
One of the point is that if you want to manage persistance, or if you want to have information you can dispatch to all players, you need to use a third party server for this (for chat purpose too for example, because you must know all players who are playing to the game).

I ve found piece of code to write a nodejs server. For the moment, it is the easiest way (if you know javascript of course) to write an external third party server. It is light, easy to write, and enough for my purpose.
This server will:
-- receive connection
-- receive TCP message
   -- receive login message
       -- check if the login/password are ok in database
       -- send a json to the sender by TCP message



var net = require('net');
var mysql = require('mysql');

var mySqlClient = mysql.createConnection({
  host     : "*****",
  user     : "****",
  password : "********",
  database : "*******"
});


// Keep track of the chat clients
var clients = [];

// Start a TCP Server
net.createServer(function (socket) {
   
  // Identify this client
  socket.name = socket.remoteAddress + ":" + socket.remotePort

  // Put this new client in the list
  clients.push(socket);

  // Send a nice welcome message and announce
  //~ socket.write("Welcome " + socket.name + "\n");
  broadcast(socket.name + " joined the chat\n", socket);

  // Handle incoming messages from clients.
  socket.on('data', function (data) {
    //broadcast(socket.name + "> " + data, socket);
      try{
        var val = JSON.parse(data);
        if (val.code == "1"){
            login(socket,val);
        }
      }catch(err){
            console.log("data received not in JSON format : "  + data  + "/////" + err);
      }
  });
    socket.on('error',function(){
        console.log('socket reset');
        clients.splice(clients.indexOf(socket), 1);
    });
  // Remove the client from the list when it leaves
  socket.on('end', function () {
    clients.splice(clients.indexOf(socket), 1);
    broadcast(socket.name + " left the chat.\n");
  });
 
  function login(sender,jsonObj){
      //~ console.log(jsonObj);
      var selectQuery = "SELECT * FROM table where name ='" + jsonObj.login + "' and passwd = '" + jsonObj.password +"'";
       var status=0;
        var sqlQuery = mySqlClient.query(selectQuery);
        sqlQuery.on("result", function(row) {

          status=1;
        });
       
        sqlQuery.on("end", function() {
            //~ if (status){
          //~ mySqlClient.end();
            //~ }
          sender.write('{"code":"1","status":"' + status + '"}');
        });
       
        sqlQuery.on("error", function(error) {
          console.log(error);
            sender.write('{"code":"1","status":"-1"}');
        });

  }
 
  // Send a message to all clients
  function broadcast(message, sender) {
    clients.forEach(function (client) {
      // Don't want to send it to sender
      if (client === sender) return;
      client.write(message);
    });
    // Log it to the server output too
    process.stdout.write(message)
  }

}).listen(5000);

// Put a friendly message on the terminal of the server.
console.log("Chat server running at port 5000\n");







 

vendredi 22 janvier 2016

ue4 multiple level zoning, and architecture

It is important to understand how ue4 works to make a multiplayer game.
A dedicated server runs only one level (physics, replication, ...).
You have multiple possibilities. If all your players are changing of zone at same time, and the zone is loaded only at this moment, your server can change zone, and load it, and the clients will do the same.
One server is enough

But if you wish to have several zone running at same time, you must keep in mind, that you must have one dedicated server per zone.
The client will connect to the server it needs at the moment it wants.
From my side, when client is launched, it is not connected. It shows a level with a tiny scene, and an UI to fill knickname, and a button to connect.
Once player clicks on connect, I send a connection to the first server using IP and port.
it is enough. Once connected, the server will send the level to load, and replicate actors which need to be replicated.

during game, maybe player wish to change zone, to travel elsewhere. I will disconnect to current server, probably load a temporary level, with tiny scene, to wait connection to other server, and then I will connect to a new IP/Port, to reach the new server hosting the level I want to travel to.
Once again, the server will send the name of level to load, and replicate what it needs.

Finally it is quite standard as an architecture, but you don't have choice, it is way to do.

I got a question on instantied zone. I think best way is to have a running server by instance too.

UE4 packaging

The first times I packaged my game, I was totally afraid by the time it took. on my laptop, it was between 1 and 2 hour, with very lot of steps.

Looking at log, I saw that lot of components was taken in the package, html5, VR, ... and so on, what the hell, I have no needing of all of this.

For information, all this components are standard plugin in ue4 editor. So just go to plugins menu, and disabled all you don't need. your package will be better, and you will package quicker :D


vendredi 8 janvier 2016

Networking : day 3 : torque

After moving forward, next step is to rotate on 2 axis (I choosed 2 for more convenient, I don't like roll :p).

As seen before, the keyboard input are given on client side, and the physics is managed on server side.
So the input must be treated on remote, and the modification value done on server.

First, create input in project settings : using QD and ZS.













Next, we will in pawn blueprint, create an addTorque server event (custom event), running on server, with a vector in input.



 Now we can react at leftright event, and calculate the vector to apply torque



Notice the switch has autority... It is keyboard input, so we have to use remote activity.
 And now, we have to apply torque server side



I think switch has authority is not necessary here, it is more convenient to show example...

Finally, we will catch updown event, to pitch the spaceship


 Done...

For now, you can speed up to go forward, apply torque to turn right/left, or up/down.

Because you are using physics, reaction on bouncing, will be quite realistics

mercredi 6 janvier 2016

networking ue4 : day 2

You got speed management... but now how to move your pawn?

First of all, check that your spaceship is using physics... Go to your pawn blueprint, and look at your static mesh


Check simulate physics, put linear and angular damping at 1, to have enough frictions, to slow your ship in rotation or movement (otherwise it will speed very highly, and rotate very quickly... :p)

It is a space game, I disabled gravity.

Physics is important  on server, but totally unusefull on client, so desactivate it, on begin play event.



As you see you choose remote on switch autority, to disable physics simulation only on client side.

I am using physics because, I wish to have bounce behavior, collision, and so on. So I will add Force to my mesh, to make it move forward.
I will do this on server



And this is it, your pawn is moving. But client didn't see the move...
I created a custom event, I will use to broadcast the new position/rotation to client. I give to it, vector and rotator as parameter.
Multicast == broadcasting


On server side, I will get my rotation, and location, and give it to my custom event. Custom event will run on client side, I set to my mesh, the new position and location.


Global schema is this
































ue4 : networking day1

The aim of my game is to do a multiplayer game, with a dedicated server and clients.

It was sometimes hard to find my way, to understand networking in unreal engine, so I will try to take time to explain different things about networking, and to illustrate what I 've done in my game about the different topic.

If you need, more precise focus, let me know.

First of all, because it is dedicated server, server has control over all things. You have to draw blueprint in same blueprint for case of "server", and case of "client".

It is important to understand this. It is important also to understand what will be managed by server and replicated to client, and what is manage by client.

On client board, you will manage essentially UI, special effects, keyboard/mouse input management...
Server will manage AI, movement, physics, spawning, ...

So every time, you wish to move your pawn, through keyboard input, you will have to send the information to server, which will move the pawn, and replicate/broadcast new position.

Ok with this very few basics...

First, I will show you how to manage increase/decrease speed on my spaceship.
First I create new input in project settings








 Next in my pawn Blueprint, I create two variables, speed, and speedmax.
Speed will be replicated. It is an information needed by client to manage UI and FX for example.
Replication is always from server to client.



I ve created next a new custom event in my blueprint. The event receives the new speed, and set the variable with it.
Event must be run on server



 Finally, I receive my speed input (through A or W keyboard input), and I manage the increase of speed, and send it to server.





Pay Attention on switch authority. Switch authority allows to run what is after on server, or client. Here, because it is a client input, I have to manage following on client. So I choose remote.
If it was an event about collision for example, I must switch on authority, to manage it only on server.

If you don't use this switch, it will be run on both (client and server), and you can have strange behavior or maybe error. For example, if you manage to update an UI, on dedicated server, you will have errors, because there is no window for server.

Here, you will manage keyboard input to increase speed, and send the update to server.
Server will update speed variable, and because of that, the update will be replicated to all client.

To do better, you can send the input to server, which will manage the different test case, to be sure and guarantee no cheat :D


























mardi 5 janvier 2016

ue4 scalablity : graphics settings

It is quite easy to change graphical settings if you are launching your game in PIE, through menu configurations.

But for dedicated server + game, you have to used command line, using ue4editor yourproject yourmap -game or -server.

It is possible to change graphical settings in blueprint, launching command console as this :


















You can use ini files to manage this, and save user settings.



















 Be sure to create a paragraph  Scalabilitygroups
[/Script/Engine.GameUserSettings]
bUseVSync=False
ResolutionSizeX=1600
ResolutionSizeY=900
LastUserConfirmedResolutionSizeX=1600
LastUserConfirmedResolutionSizeY=900
WindowPosX=-1
WindowPosY=-1
bUseDesktopResolutionForFullscreen=False
FullscreenMode=2
LastConfirmedFullscreenMode=2
Version=5
AudioQualityLevel=0

[ScalabilityGroups]
sg.ResolutionQuality=25
sg.ViewDistanceQuality=1
sg.AntiAliasingquality=1
sg.ShadowQuality=1
sg.postprocessquality=1
sg.TextureQuality=1
sg.EffectsQuality=1


And the 6 parameters at bottom are from 0 to 3 (3 is epic graphisms, 0 lowest level).
resolutionquality can be put from 0 to 100.








lundi 4 janvier 2016

Targeting Hud :reticle, floating name

Something important is to have a targeting system, and have a reticle around ennemies.

It is quite easy in ue4, because you have a function to transform 3D position to screen position.

First step, import your reticle, or crosshair as a texture into your content browser.

I suppose you've created your own HUD blueprint, and load it as default to your map.

Open your HUD blueprint.

You will react at receive draw HUD event.

I've created a pawn BP, for my ennemies, with a static mesh inside. Nothing more is needed for this paper.

First step,  I will loop through all actors with the class myEnnemyPawnBP and for the remaining, I think a picture is enough to understand.
I put the reticle around the ennemy (so the minus 35 because my reticle make 70*70 pixels), and I put its name above the reticle in red.






Emissive material through blueprint

Hello,

Something fun is to use emissive material. I got a static mesh, with a material containing texture, bumping, and emissive texture.

It is allowing you to make shine some parts of your mesh, without managing lights (as an external object).

My purpose was to make shining the engine when speed up.

First step is to modify your material, to add a parameter (scalar parameter) and multiply it to the emissive texture.






Next, go out of the texture, go back to content browser, right click on your material, to create a material instance.

In previous step, I've created a pawn blueprint, with speed and speedmax variable, and with a static mesh component referencing my mesh.

Open this blueprint, at the begin play event, create a dynamic material for your static mesh.
Fill the source material, with the name of your instantiated material, you created step before.




Every tick, I check the speed, to make glowing engine or not.

I calculate a prcent speed, to make shine depending of the engine's power, I retrieve material from my mesh (here my mesh has only one material, so it is easy, I retrieve materials at index 0)
I cast to material instance dynamic, and I use set scalar parameter value, where I precise the parameter created in first step into my material.




Now in game, if you increase the speed, engine will shime more and more...
Hello,

New beginning for shimstar... again
All these years, I grew up my skills around 3D, networking, game design... and I made something very cool around shimstar on panda3d. I think I have something quite mature, and I am proud of this, because I wrote lot of code to be at this step.

But I choosed to do a restart using a game engine mature, known of the market. It is long time I looked at Unreal Engine, and because of this, I choosed to use it for this next step.
Unity was another choice possible... but for different reasons, not all very consistent, I choosed unreal engine 4.

On this first step, I think I will try to create something simpler than a mmorpg :D
I will keep the multiplayer stuff, and implement some missions to do with AI. Once in space, you will have things to do, linked between them. For example, once you kill the first enemies, you will have to reach a point to protect something, ... and so on.

My feelings after 3 months, is that unreal engine is not for totally beginners. I think if you have a good background on 3D, graphisms, gameplay, it will enhance your ability to build a good game, otherwise you will spend lot of time to do something, that anoter engine can do easier.

I will use this blog, to show some stuff  I do with unreal engine. Lot of things can be done without coding, using a workflow tools named blueprint.

I hope it can be usefull for other people.