gamedev

Unreal Engine – Installation and folder structure

Unreal Engine – Installation and folder structure

Installation

1. Install Visual C++ Redistributable Packages for Visual Studio 2013, you can find it at: http://www.microsoft.com/en-us/download/details.aspx?id=40784

Download and install vcredist_x64.exe for 64 bit OS

The Visual C++ Redistributable Packages install run-time components that are required to run C++ applications that are built by using Visual Studio 2013.

If you do not install the package you will have the message ‘MSVCP120.dll is missing from your computer’.

2. Install Unreal Engine

Installation Folder Structure

If you use the installation folder C:/UnrealEngine, you will find some important folders inside:

/Engine/Binaries/Win64/UE4Editor.exe -> execute this to start the editor

/Samples/StarterContent
/Architecture -> *.uasset (unreal assets) – risorse
/Audio
/Blueprints
/Maps
/Materials
/Particles
/Props
/Shapes
/Textures

/Templates
/TP_2DSideScroller -> based on C++ -> you need Visual Studio 2013 installed to compile
/TP_2DSideScrollerBP -> based on Blue Print -> visual scripting, do not require additional software
/TP_FirstPerson
/TP_FirstPersonBP

Project Folder Structure

If you store your project on D:/Unreal you will find

/Yourproject
/YourProject.uproject (unreal project)
/Config -> configuration files for Editor, Engine, Game, Input
/Content -> your *.uasset, Animations, Architecture, Audio etc…
/DerivatedDataCache
/Intermediate
/Saved

By |Unreal Engine, Video Games Development|Commenti disabilitati su Unreal Engine – Installation and folder structure

Unreal Game Engine – C++ Programming – Quick Start Guide

Unreal Game Engine – C++ Programming – Quick Start Guide

C++ (pronounced cee plus plus) is a general purpose programming language. It has imperative, object-oriented and generic programming features, while also providing the facilities for low level memory manipulation.

Unreal Engine does not have an internal code editor, you need to install Visual Studio od Visual studio Express.

1. Install the latest version of Internet Explorer
2. Install Visual Studio Express
3. Run Visual Studio

Increase the width of the Solution Configurations dropdown menu:
a. Right-click on the toolbar and select Customize (Personalizza) at the bottom of the menu that appears.
b. Click on the Commands tab (Comandi).
c. Select the Toolbar (Barra degli strumenti) radio button.
d. In the dropdown next to Toolbar, choose Standard.
e. In the Controls list at the bottom, select the Solution Configurations control (Configurazioni soluzione).
f. Click Modify Selection (Modifica selezione) on the right. Set the Width (larghezza) to “200”.
g. Click Close. Your toolbar should update immediately.

Add the Solution Platforms dropdown
Find the right-most button on the Standard toolbar, which opens a dropdown menu that will allow you to add and remove buttons from the toolbar.
Click the dropdown button, hover over Add or Remove Buttons, and then click on Solution Platforms (Piattaforme soluzione) to add the menu to the toolbar.

Turn off the Error List window
With Unreal Engine, the Error List can display false error information.

a. Close the Error List window if it is open.
b. From the Tools menu, open the Options dialog (Strumenti> Opzioni).
c. Select Projects and Solutions (Progetti e soluzioni) and uncheck Always show error list if build finishes with error (Mostra sempre Elenco errori se la compilazione finisce con errori).
d. Click OK

Create a New Project

1. Open Unreal Editor> New Project> Blank, name it ‘CodeTestProject’ uncheck ‘Include starter content’, click on ‘Create Project’ button

Add a New Class

1. MAIN TOP MENU> File> Add Code to Project> Actor
2. Name it ‘HelloWorldPrinter’> click ‘Create Class’ button, it will create in your project folder:
– HelloWorldPrinter.h (header)
– HelloWorldPrinter.cpp (c plus plus source)
3. In the next floating window click ‘Yes’ to edit now, Unreal will run Visual Studio Express

Visual Studio takes several minutes to analysing files, includes etc…, at the end you will se the message ‘Ready’ (Pronto), in the RIGHT COLUM> Solution Explorer (Esplora Soluzioni) you will see Games/CodeTestProject

Write the code:

HelloWorldPrinter.h


#pragma once

#include "GameFramework/Actor.h"
#include "HelloWorldPrinter.generated.h"

/**
 * 
 */
UCLASS() // Questo rende Unreal Engine consapevoli della vostra nuova classe
class CODETESTPROJECT_API AHelloWorldPrinter : public AActor
{
	GENERATED_UCLASS_BODY()

	UPROPERTY() // Questo rende Unreal Engine consapevoli della vostra nuova proprietà
	int32 MyNumber; // declare an integer variable

	virtual void BeginPlay() override;// Questo codice dichiara una funzione, ma lo fa eseguendo l'override di una funzione dalla classe padre.


};// END UCLASS

HelloWorldPrinter.cpp


#include "CodeTestProject.h"
#include "HelloWorldPrinter.h" 

//Your class constructor
AHelloWorldPrinter::AHelloWorldPrinter(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	MyNumber = 12;
}

// Dichiara la funzione - eseguita in BeginPlay() che è la funziona che unreal esegue all'inizio del game
void AHelloWorldPrinter::BeginPlay()
{
	Super::BeginPlay();

	if (GEngine) // Controllo se è valido l'oggetto globale GEngine
	{
		// Visualizza il testo a video
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Hello World!"));
		// Visualizza la variabile MyNumber
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(MyNumber));
	}
}

Save All

Compile the code

1. RIGHT COLUMN> Solution Explorer (Eslora Soluzioni)> RMB over yourproject (|++|CodeTestProject)> Build (Compila)

The process can take several minutes because it compile all the dependencies.

Using the New Class

1. Close Unreal Editor
2. Reopen the Unreal Editor and reload the Project
3. MAIN TOP MENU> Class Viewer> Filters> uncheck ‘Blueprint Bases Only’, search ‘HelloWorldPrinter’
4. DRAG and DROP Actor>HelloWorldPrinter (the Sphere icon), from the Class Viewer into 3D Viewport.
5. Play

Change the Class

1. Close Unreal Editor (if you do not close the Unreal Editor, Visual Studio can not overwrite the old file)
2. Inside Visual Studio open HelloWorldPrinter.cpp
3. Change … Yellow, TEXT(“Hello World!”) to …Yellow, TEXT(“Hello World Two!”)
4. RMB over yourproject (|++|CodeTestProject)> Build (Compila), the process takes only few seconds.
5. Reopen Unreal Editor
6. DRAG AND DROP Actor>HelloWorldPrinter (the Sphere icon), from the Class Viewer into 3D Viewport.
5. Play

Reference: https://docs.unrealengine.com/latest/INT/Programming/QuickStart/1/index.html

Editing an existing Project on the fly

0. Open Visual Studio> TOP TOOLBAR> Solutions Configurations (Configurazioni soluzioni)> DebugGame Editor
Questo significa che possiamo debuggare e aprire il progetto direttamente

1. Open Visual Studio Express> MAIn TOP MENU> File> Open Project (Apri Progetto)> select ‘CodeTestProject.sln’
2. RIGHT COLUMN> Solutions Explorer> click over Games/CodeTestProject/Source/HelloWorldPrinter.cpp
3. Change the script and save it
4. RIGHT COLUMN> Solutions Explorer> RMB over Games/CodeTestProject> Debug> Run New Instance (Avvia Nuova Istanza)

5. Unreal Enditor will be opened

Play to see changes

6. Switch to Visual Studio, change the script, save it.
7. Switch to Unreal Editor, MAIN TOP TOOLBAR> Compile> Recompile Game Code (Recompile and Reload C++ code on the fly)

Play to see changes
4. File> Save HelloWorldPrinter.cpp

For italian people: come funziona?

1. Visual Studio viene settato per permettere il debug direttamente all’interno di Unreal editor con ‘Configurazioni soluzioni> DebugGame Editor’
2. da visual Studio creo un ponte verso Unreal Editor con ‘Avvia Nuova Istanza’
3. da Unreal Editor posso ricompilare al volo direttamente dall TOOLBAR superiore con ‘Recompile Game Code’

By |Unity3D, Video Games Development|Commenti disabilitati su Unreal Game Engine – C++ Programming – Quick Start Guide

Unity3D – Object Pooling – Bullets – CSharp

Unity3D – Object Pooling – Bullets – CSharp

Object Pooling è una tecnica per ridurre i calcoli della CPU.

Questo sistema di programmazione consiste nel creare un gruppo di oggetti, storarli inattivi all’interno di una lista, per poi attivarli e posizionarli direttamente nell’area di gioco.

La generazione di tutti gli oggetti comporta un consumo di RAM iniziale elevato, che comunque è molto meno costoso in termini di prestazioni del dover ogni volta istanziare e distruggere i singoli eggetti.

Applicare questa tecnica ha senso se utilizziamo a video nello stesso tempo almeno diverse centinaia di oggetti o stiamo sviluppando su piattaforma mobile dove la potenza di calcolo della CPU non è elevata.

Creiamo una scena con:

(parent) Spaceship
– (child) Bullet

All’oggetto ‘Bullet’ applichiamo:

BulletScript.cs


using UnityEngine;
using System.Collections;

public class BulletScript : MonoBehaviour {

	public float speed = 5;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		// simple move the object
		transform.Translate (0, speed * Time.deltaTime, 0);
	
	}

}// END MonoBehaviour

Questo script semplicemente muove l’oggetto

BulletDestroyScript.cs


using UnityEngine;
using System.Collections;

public class BulletDestroyScript : MonoBehaviour {

	// This function is called when the object becomes enabled and active.
	// It is a part of MonoBehaviour.OnEnable()
	void OnEnable()
	{
		Invoke ("Destroy", 2f); // call the function after 2 second
	}

	void Destroy()
	{
		gameObject.SetActive (false); // deactivate the object
	}

	// This function is called when the behaviour becomes disabled () or inactive.
	// It is a part of MonoBehaviour.OnDisable()
	void OnDisable()
	{
		CancelInvoke();
	}
	
}// END MonoBehaviour

Questo script disattiva l’oggetto dopo 2 secondi per ottimizzare il rendering

All’oggetto ‘Spaceship’ applichiamo:

BulletFireScript.cs


using UnityEngine;
using System.Collections;
using System.Collections.Generic; // to add Lists

public class BulletFireScript : MonoBehaviour {

	public float fireTime = .1f; // attiva un oggetto bullet ogni xxx secondi
	public GameObject bullet; // Assign in Inspector

	public int pooledAmount = 20; // numero di oggetto instanziati, se insufficienti aumentarli 
	public List<GameObject> bullets;

	// Use this for initialization
	void Start () {
		// crea una lista di oggetti inattivi
		bullets = new List<GameObject> (); 

		for (int i = 0; i < pooledAmount; i++) 
		{
			GameObject obj = (GameObject)Instantiate(bullet);
			obj.SetActive (false); // inattivi, verranno attivati dalla funzione Fire()
			bullets.Add (obj); // aggiungi l'oggetto alla lista
			Debug.Log(bullets.Count);
		}
		InvokeRepeating ("Fire", fireTime, fireTime); // richiama la funzione Fire()
	}// END Start

	void Fire() {
		// posiziona e attiva tutti gli aoggetti della lista bullets
		for (int i=0; i < bullets.Count; i++)// scorre tutti gli oggetti della scena
		{
			if (!bullets[i].activeInHierarchy)// se un oggetto nella scena non è attivo
			{
				bullets[i].transform.position = transform.position;// posiziona
				bullets[i].transform.rotation = transform.rotation;// rotazione
				bullets[i].SetActive(true);// attiva
				break;			
			}// END if
		}
	}// END Fire

}// END MonoBehaviour
	

Assegniamo in Inspector l’oggetto ‘Bullet’ alla variabile ‘bullet’

Questo script:
1. Crea una lista
2. Start () -> Instanzia 20 oggetti, li disattiva e li inserisce nella lista
3. Fire() -> posiziona gli oggetti e li attiva

Avviate il gioco, osservate Hierarchy e Inspector per BulletFireScript.cs per comprenderne il funzionamento

Si può notare dal codice di tutti gli script che – Destroy (gameObject) – NON è mai stata utilizzata, perchè i 20 oggetti bullet vengono continuamente riciclati attivandoli e disattivandoli di continuo.

By |Unity3D, Video Games Development|Commenti disabilitati su Unity3D – Object Pooling – Bullets – CSharp

Unity3D – Drivable Vehicle – JavaScript – Super Easy

Unity3D – Drivable Vehicle – JavaScript – Super Easy

Create a scene with:

– (parent) CarBody (Box Object) -> Add Rigid Body -> Mass 200
– (child) CarWheelFR (Empty Object) -> Add WheelCollider
– (child) CarWheelFL (Empty Object) -> Add WheelCollider
– (child) CarWheelRR (Empty Object) -> Add WheelCollider
– (child) CarWheelRL (Empty Object) -> Add WheelCollider

CarBody, add the script:


#pragma strict

// Assign in Inspector
var CarWheelFR : WheelCollider; // Front Right
var CarWheelFL : WheelCollider; // Front Left
var CarWheelRR : WheelCollider; // Rear Right
var CarWheelRL : WheelCollider; // Rear Left

var Speed: float = 10; 
var Breaking: float = 20; 
var Turning: float = 20; 

function Start () {
}// END Start

function Update () {
	// This code makes the car go foward and backward - notare che è a trazione posteriore
	// simulate the whell rotation - spinta
	CarWheelRR.motorTorque = Input.GetAxis("Vertical")*Speed; // arrow up / down
	CarWheelRL.motorTorque = Input.GetAxis("Vertical")*Speed;
	
	// reset the variable, if you miss this code 'CarWheelRR.brakeTorque = Breaking;' for ever after get Space key button
	CarWheelRR.brakeTorque = 0;
	CarWheelRL.brakeTorque = 0;
	
	// This code makes the car turn
	// simulate the steer - sterzata
	CarWheelFR.steerAngle = Input.GetAxis("Horizontal")*Turning; // arrow left / right
	CarWheelFL.steerAngle = Input.GetAxis("Horizontal")*Turning;
	
	if (Input.GetKey(KeyCode.Space))
	{
		// simulate the brake, frenata
		CarWheelRR.brakeTorque = Breaking;
		CarWheelRL.brakeTorque = Breaking;
	}
	
}// END Update

Assign in Inspector var CarWheelFR CarWheelFL CarWheelRR CarWheelRL

Play

For italian people: come funziona?
1. Monto l’auto con il corpo e le ruote, imparentando le ruote a CarBody, come nella realtà
2. Con l’input da tastiera sfrutto le proprietà del Collider WheelCollider: .motorTorque .steerAngle .brakeTorque

Vedi API a: http://docs.unity3d.com/ScriptReference/WheelCollider.html

By |Unity3D, Video Games Development|Commenti disabilitati su Unity3D – Drivable Vehicle – JavaScript – Super Easy

Unity3D – Inventory System – Basic

Unity3D – Inventory System – Basic

You need an Inventory System for your last FPS or for your graphic adventure?
This is the basic code to start!

Create a scene:

– Empty Object, rename it ‘GameController’ and attach:
– Inventory.js
– GameControllerScript.js

Inventory.js:


#pragma strict

var inventory = new ArrayList(); // declare the ArrayList

function Start () {
}// END Start()

function Update () {	
}// END Update()

GameControllerScript.js


#pragma strict

private var inventoryScript : Inventory; // variable to store another script
 
function Awake ()
{
    inventoryScript = GetComponent(Inventory); // get script 'Inventory'  
}// END Awake()

function Start(){
    // add to script 'Inventory'> var inventory = new ArrayList();
    inventoryScript.inventory.Add("pistol"); //add item to inventory
    inventoryScript.inventory.AddRange(Array("key", "key", "ammo", "ammo")); //add multiple items
    inventoryScript.inventory.Sort(); //sort inventory
    inventoryScript.inventory.Remove("ammo"); //remove first instance of item
}// END Start()
 
function OnGUI(){
    //display inventory by converting it to an array
    GUI.Label(Rect(0,0,400,50), "Inventory: " + Array(inventoryScript.inventory)); 
    // the result is -> Inventory: ammo,key,key,pistol
}// END OnGUI()

Play, the result is -> Inventory: ammo,key,key,pistol

For italian peolple: Come funziona?

Super facile, creo un’ArrayList() ed aggiungo e tolgo contenuti.
ArrayList() è 5 volte meno performante di un Built-in Arrays ma estremamente più dinamico infatti:
– ha una dimensione dinamica, per aggiungere e togliere contenuto dinamicamente
– accetta dati di tipo misto
– presenta funzioni più avanzate di JS Arrays vedi documentazione Microsoft ufficiale a:
http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx

By |Unity3D, Video Games Development|Commenti disabilitati su Unity3D – Inventory System – Basic