Dev Stories: is Unity OnGui still good?

Okay so here’s the million-dollar question for you guys:

What game mechanic is used in every RTS, RTT or any game, in which you have to control your soldiers, goons or minions or any sorts of units?

Yep you guessed it right, and there’s no official(at least that I'm aware of) name for it. We at Golden Fox call it The Box Selection.

As you may already know, NEILA is an Action RPG with strategic game elements. This means you get to control your goons alongside the main hero. We are obviously in need of a precise Box Selection. Also, we need it in our level editor DragonFly too. That’s where we faced an issue for the first time. The thing is that our selection works just fine, but it’s still not quite there in terms of performance, selection box appears a little late after the mouse click.



If you look closely, you will notice tiny lag before the rectangle shows up. In bigger scenes, it becomes almost unusable.

And here’s how the code looks like:

private void Update()
   if (Input.GetMouseButtonDown(0))
private void SaveMouseStartingPosition(Vector3 startingPos)


At first, I thought that the problem was with Selection Rect itself, but that wasn’t the case. I dug it up and what do you know? The problem was Unity’s Input System itself. It depends on Frame rate and Selection is a little too late most of the time.

I’ve tried to save the mouse position on each Update() call, to compare them in the next, but that was a really bad solution. I also tried to use FixedUpdate(), but it didn’t help either. So I asked myself, what’s called more often than Update() or FixedUpdate()? After a subtle blackout, the Eureka moment kicked in!
It is OnGui ffs, It can be called several times per each frame and it can detect mouse click almost instantly.

Here's the code:

private void OnGUI()
        var e = Event.current;
        if (e.button == 0 && e.isMouse)

    private void SaveMousePositionOnBoxSelectionStart(Vector3 mousePos)




This how I solved the box selection performance problem. Really simple. I hope you will find it, useful guys.  If any of you have encountered a similar problem or found a better workaround to the problem let me know in the comments down below.

Signing out,


Dev Stories: Living on a Single Thread

Loading a lot of Objects or executing a lot of tasks as fast as possible in conjunction with keeping your app responsive - has always been a challenge when you only have a Single Thread at your disposal, as you have to manage timing for suspensions and switching between tasks.

Most modern apps don't have this problem, as they run in Multiple Threads which are seemingly communicating with each other.

In many cases the  User Interface (UI) is drawn in Main thread and tasks are executed in parallel background threads, making UI rendering independent of background tasks. Meaning that, if background task hangs, UI will still keep running i.e. stay responsive and capable of informing the user of what's going on.

Unfortunately Unity is not thread safe(as of Aug, 2018) - all calls to Unity API should be done only from Main Thread , otherwise you'll probably get an Exception. (Yes  I'm aware of the Jobs system and it's awesome, but not quite there yet)
There is also one more thing to note: in Unity  order of execution of certain functions really matters sometimes and we can’t run them in parallel.

We had an issue with generating a lot of mesh files and textures from our custom serialized format (files were loaded in parallel, but generation of unity objects was serial). If we generated them all at once without waiting for UI redraw – Progress Bar would freeze until very end of the operation, which kinda killed the sole purpose of having a progress indicator.


Image: Progress bar freezes until the very end (10x fast forward)

That could be fixed by waiting for the end  of the frame for each file. Though we will waste a lot of precious time for no reason.


Image: Waiting for the end  of the frame for each file

The goal was to generate as much objects per frame as possible. Also to give UI some time to redraw, before continuing with object generation.

To do this I created a “Loop Slicer”, which slices loops into chunks. Each chunk has around 16ms (Less than 1 Frame time on 60FPS, I will experiment with this later) to execute. UI callbacks are executed between each chunk.

Implementation is very simple;  Loop checks the timer before going to next index and will be paused if 16ms limit was exceeded. It will continue After executing callback and waiting for passed waiter.


Image:  Loop Slicer Chunks

I short Loop slicer’s main purpose is to split a bunch of little tasks between frames in the most efficient way possible(at least for me lol).

And that's about it for today guys.
Oh and just in case you find this useful here's the download link:

Feel free to leave a comment down bellow if you have any questions, issues or just found a bug haha.

- Patik


Welcome to Golden Fox Games Blog


We're Golden Fox Games, an independent game studio based in Tbilisi, the country of Georgia.

This is supposed to be an introductory blog post, so let’s not talk about how hard it is to make games and CREATE an actual studio and the indie philosophy in general. Maybe next time.

We’re a privately held studio. Co-founded in 2015 by a couple of guys with Business, Marketing, Art and Media and of course die hard gamer background.

We're working on an Action RPG game called NEILA for digital download platforms that we hope to release in foreseeable future. We will be discussing the actual game in upcoming posts thus keeping you guys up to date on our progress.

Posts will cover everything including (but not limited to):   Programming, Game Design, Level Design, Concept art, Storytelling, Sound design etc.

So sit tight and stay tuned! It’s going to be a fun ride!

You can also follow us on Twitter and Facebook

- Golden Fox