Recent Articles

Knight AND Elfs: The fight for the jewels

Knight AND Elfs: The fight for the jewels is a short Game 2D Platform , where basically the user controls a character responsible for to kill elfs and to recover the jewels stoled of your people that were stolen.

The game has support for two languages english and portuguese.

The game at this moment is in final phase of development, so we just need to add sounds, and a better font in the texts.

Credits
Programming
Mauro Ubaldo
Art
Art Knights Clan
Super Brutal Assets
Game Art 2D
Craftpix.Net

The Game Menu
How to play
Personalization’s screen
Cutscene with custom character, and custom name.
Gameplay with custom character.

Mutants In The Space

Mutants in the space is a short shooter game demo, that is being developed with Unity 2021 and HDRP, this game don’t have history, but is based in idea when exists mutants in a spacial station, and the Player needs to kill all mutants.

All assets of 3D, and textures were downloaded from the Unity asset store, due to the process of building the game, all credits will be inserted at the end of development, since any thing can be changed.

Begin Hall
Boss Room – Part 1
Boss Room – Part 2
Boss Room – Part 3
Enemies Room 1 – Part 1
Enemies Room 1 – Part 2
Action Version 1
Action Version 2
Showing the second room created
Showing the test in Second Room
Showing all parts of the level
Showing all parts of the game, with exception of bossfight
Inserting KillMark for headshots

Showing the Unity Test Runner

This is a series of articles that will talk about Unit Test and Unity Test Runner.

For this Article, I will show Unity Test Runner.

How to enable Unit Test Runner

For to open Unit Test Runner, you can make it this way:

Window > General > Test Runner

After the window of the test, the unity will show the test runner.

The Unit Tests with unity can be made in PlayMode and EditMode

According to Unity Documentation

The Play Mode: You can run Play Mode tests as a standalone in a player or inside the Editor. Play Mode tests allow you to exercise your game code, as the tests run as coroutines if marked with the UnityTest attribute.

The Edit Mode: tests (also known as Editor tests) are only run in the Unity Editor and have access to the Editor code in addition to the game code.
With Edit Mode tests it is possible to test any of your Editor extensions using the UnityTest attribute. “

You can see more info about this in the official documentation here: https://docs.unity3d.com/Packages/com.unity.test-framework@1.1/manual/edit-mode-vs-play-mode-tests.html

For this article, I only will show it with PlayMode.

So let’s go to create the Test Folder, and select the option Create PlayMode Test Assembly Folder.

Now, you can see that Unity created a folder named Tests in your project.

If you open the folder, you will see that exists a Unity assembly (Don’t worry the Unity’s documentation has an explanation for this, and you will see it below).

What is Assembly?

According to Unity Documentation, An assembly is a C# code library that contains the compiled classes and structs that are defined by your scripts and which also define references to other assemblies.

If you want to learn more about Assemblies you can see the official documentation here: https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html#create-test-assembly

Now select the option Create Test Script In Current Folder.

Repair that in your folder a script has been created.

Now see that in your Test Runner Window, new content has been showing, this is the test methods written by Unity when our test script is created, I will talk more about this in the next article don’t worry.

So for this article, in the next article, I will open the test script, and I will talk about how to write unit tests, and which test framework we can use for this.

Follow me on Instagram to stay known when I create new posts.

You can also leave your feedback, and suggestion, I will read them all, and I will answer for you.

Thanks for reading.

Job System – Part 2

This is the second part of my series of articles about Job System, you can read my first article here:

https://mauroubaldo.com/job-system-part-1/

Now let’s talk about Native Containers with Jobs.

For Start this article I would like a quote from Unity’s official documentation, about what is Native Containers.

“A Native Container is a managed value type that provides a safe C# wrapper for native memory. It contains a pointer to an unmanaged allocation. When used with the Unity C# Job System, a Native Container allows a job to access data shared with the main thread rather than working with a copy.” Unity Documentation.

For more Infos, you can see the official documentation here: https://docs.unity3d.com/Manual/JobSystemNativeContainer.html

Now that we know what are Native Containers, we can talk about the types of native containers.

What are the types?

According to Unity documentation, the types are:

NativeArray – This is responsible for exposing a buffer of native memory for managed code.

NativeList – This is a resizable native array.

NativeHashMap – These are keys and value pairs.

NativeMultiHashMap – These are multiple values per key.

NativeQueue – This is a queue.

For more Infos you can see the official documentation mentioned in this part of this article:

NativeArray: https://docs.unity3d.com/ScriptReference/Unity.Collections.NativeArray_1.html

NativeCollections: https://docs.unity3d.com/Manual/JobSystemNativeContainer.html

For this article, I will only show the native array, because the native array does not need a preview package, but if you want to see other collections, you can search for Entity Component System (ECS) package.

How does it work?

Firstly you need to import the namespace Unity.Collections, at the moment that I am writing this article the Unity Engine only has available the NativeArray but in Entity Component System (ECS) package as mentioned, exist other Collections.

For this Article, I will use NativeArray.

Creating a NativeArray

For to create a NativeArray you only need to make this:

NativeArray<int> myNativeArray;

How to initialize a Native Array?

You can initialize a native array thus:

myNativeArray = new NativeArray<int>(arrayLenght, Allocator.Persistent);

Or using some constructor, NativeArray has three constructors, they are:

        public NativeArray(T[] array, Allocator allocator);
        public NativeArray(NativeArray<T> array, Allocator allocator);
        public NativeArray(int length, Allocator allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory);

Repair that We need to define an allocator, and Now I will explain what is this.

An Allocator is an Enumerator used to specify the type of allocation for our Native Array.

Using a native collection we need to use a memory allocator type.

An allocator can have three types:

Persistent: this is a very slow allocation, but your data may be available all the necessary time.

Temp: is a very fast allocation, but your lifetime is 1 frame or minus.

TempJob: is more fast than persistent but more slowly than temp, and your lifetime is 4 frames or minus.

For more info, you can check the official documentation here: https://docs.unity3d.com/Manual/JobSystemNativeContainer.html

In this article, I only will use a Persistent allocator, because is a very simple example, but I suggest that you test other allocators, as an exercise for improving your knowledge.

Now, that We know how to create a native array, let’s talk about how to work with a NativeArray.

The way to work with native arrays is the same as in other fields, but with a particularity, with the native array, you can copy values and paste them into other variables, after the end of the Job.

For example:

using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;
using Unity.Jobs;

public class JobExample2 : MonoBehaviour
{

    NativeArray<int> myFirstNativeArray;
    NativeArray<int> mySecondNativeArray;
    NativeArray<int> myResultNativeArray;
    int[] myFirstArray;
    int[] mySecondArray;
    public int[] myResultArray;

    MyJobWithArray myJobWithArray;
    JobHandle myJobWithArrayHandle;

    struct MyJobWithArray : IJob
    {

        public NativeArray<int> myJobNativeArray;
        public NativeArray<int> myJobNativeArray2;
        public NativeArray<int> myJobResultNativeArray;

        public void Execute()
        {
            for (int i = 0; i < myJobNativeArray.Length; i++)
                myJobResultNativeArray[i] = myJobNativeArray[i] + myJobNativeArray2[i];
        }
    }

    void Awake()
    {

        myFirstArray = new int[] { 1, 2, 3, 4};
        mySecondArray = new int[] { 5, 6, 7, 8 };
        myResultArray = new int[4];

        myFirstNativeArray = new NativeArray<int>(myFirstArray, Allocator.Persistent);
        mySecondNativeArray = new NativeArray<int>(mySecondArray, Allocator.Persistent);
        myResultNativeArray = new NativeArray<int>(myResultArray, Allocator.Persistent);

        myJobWithArray = new MyJobWithArray
        {
            myJobNativeArray = myFirstNativeArray,
            myJobNativeArray2 = mySecondNativeArray,
            myJobResultNativeArray = myResultNativeArray
        };

        myJobWithArrayHandle = myJobWithArray.Schedule();
    }


    void Start()
    {
        myJobWithArrayHandle.Complete();
        myJobWithArray.myJobResultNativeArray.CopyTo(myResultArray);

        for (int i = 0; i < myResultArray.Length; i++)
            Debug.LogError(myResultArray[i]);

        myFirstNativeArray.Dispose();
        mySecondNativeArray.Dispose();
        myResultNativeArray.Dispose();
    }

}

So here you can see how to copy the data of a Job for your code without value loss.

For the last is important to see that, I am using the method Dispose, this is to deallocate the memory allocated for use of the array.

Follow me on Instagram to stay known when I create new posts.

You can also leave your feedback, and suggestion, I will read them all, and I will answer for you.

Thanks for reading.

Space Ship’s Prototype

This page was created to show a Game that is in Development.
Space Ship’s Prototype is a temporary name, this is a space shooter game.

DEVELOPMENT STATUS

FIXING BUGS FOR STABILIZE VERSION

Credits

Programming
Mauro

Models And Textures
Pulsar Bytes
Ebal Studios

UI
3d.rina

Particles
Jean Moreno