Game
Great Ape
7 years ago

Building a (in-game) level editor


Greetings,

My name is Oskar, I’m the code monkey of the Great Ape dev team. In the development process I will hopefully be of help to the other devs with their programming endeavours in the game.
My biggest, and main, task in the project though, will be the creation of an in-game level editor.
Below you will read about my first two weeks of creating my in-game level editor, enjoy!

Introduction

Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime.
— Some english person

The same could be said about a in-game level editor, possibly…
But the important thing is not that some random quote could be relevant here. What’s important is me building a level editor, from scratch.

My goal was to create some sort of editor/tool for the game I was going to work on. With Great Ape, a level editor felt like a perfect match since we want to be able to easily build levels.
This is where a level editor customized for Great Ape could be great to hopefully make level building easier!

My first go at it

I had previously worked on some simple tools in the Unity Editor so I quickly started putting together a GUI and after the first week I actually had a quite functional editor. You couldn’t do much with it other than pick blocks to place, place them and change between which level to edit.

5d0a9ccf4ab90.png

All the blocks that’s going to be available in the editor will be placed in Unity’s ‘Resources’ folder. The Resources class allows for easy access to assets you want load to the game, such as level blocks.

		
			// Gets all the prefabs in the folder at "Resources/Level Blocks"
Object[] blockPrefabs = Resources.LoadAll<GameObject>("Level Blocks");
		
	

Getting access to the prefabs was easy, and I could also get access to the small previews of prefabs you see in the editor.

5d0a9cd1d21a6.png

This was done easily with one line of code from the AssetPreview class.

		
			Texture2D previewTex = AssetPreview.GetAssetPreview(block);
		
	

For the level view in the editor I used a RenderTexture from a camera I placed in the scene. I made sure the camera used a culling mask for the layer ‘LevelBlocks’ so it would not display anything else. After that I just had to convert my mouse position from the GUI to a world position to be able to place objects in the scene.

		
			Ray mouseRay = m_cam.ScreenPointToRay(new Vector2(mousePos.x, window.height - mousePos.y));
		
	

I now had a level editor with basic functionality using Unity’s editor classes…

A change of plans

In the start of the second week I started thinking about what to do next in the level editor. I started thinking about changing the user interface and to start adding more features and stuff to the GUI. I quickly realized that a GUI of this size will be easier to design in Unity’s UI Canvas.
Then the idea came to me, I’m going to revamp my current work and make the level editor to work in-game instead!
This would make the level editor much more involved in the game since it would actually be included in the release of the game.
I remade my progress from the first week and got basically everything I already had in the editor to in-game. The biggest problems with this is that I used several Editor-only classes which I could sadly not use anymore. But except for saving the preview sprites in the Resources folder and creating the UI again, it was kinda easy to remake.
Everything else was the hard part…

5d0a9cd3e9149.png

Upcoming features/problems

The coming weeks I’m going to start implementing a menu when you select an object so you can move, rotate, scale, configure collisions and all that jazz.
I also want to add save/load features for the levels, which is hard.See, you can’t create a prefab in-game since prefabs are editor-only. The solution is to serialize the GameObjects and save them to the disk manually. I will probably look for an external solution for this.
After that I will hopefully have an easy time. Hopefully…

With all that said, I end this blog post looking forward to the progress that will be made before the next blogpost.
See you next time!

5d0a9cd65fff5.gif


0 comments

Loading...

Next up

So

i may or may not make an full art of some person or i may just leave this like that-

Here's a peaceful little forest scene for this #screenshotsaturday, from the beginning of the game.

Heya there! I really wanted to show you all a little gameplay preview of the first boss fight i'm currently working on i hope you like it ^^

Today I was setting up the location of the first boss. His name is "Father" and he is the first of the Patagonians. His task is to guard the road to the House.🛡🗡 Bookmark pre-launch page🔖🔖🔖

https://www.kickstarter.com/projects/rdvindiegame/the-patagonian…

I have added rewards for quests so that villagers can give you something in return for your hard work helping them. 🥳

I want to know - what's your favourite quest reward?

Just a Pico sprite

Back in my art school days I used to ride the 710 COPSA line from Parque Del Plata to Montevideo almost everyday. This is the Marcopolo Viaggio G4 Mercedes Benz model from the late 80s, one of the older bus models that was running on the line.

Very ambitious construction going on in Planet Zoo on Plays today. We're tryin'. LIVE: www.twitch.tv/dreamhackplays

If you’ve played the Vault demo and enjoyed it, please consider ‘liking’ the game page here on Gamejolt and/or leave a comment!

Also please consider tossing Vault on your Wishlist, I really appreciate your support!

https://store.steampowered.com/app/1251800