Game
Great Ape
6 years ago

In-game Level Editor: Inspecting & editing Objects


It’s me, Oskar, the programmer of Great Ape back again with another devlog about my in-game level editor.

Last time I talked about the save & load feature of the editor where I used a “real” dialog window to choose the location of a save file.
I finished the last log’s content before the leave for holidays so by now I have a few more things to talk about.
As the title of this post alludes to I have worked on actually editing objects in the level editor.
What I mean by editing objects is that you can currently only change their Transform values. So without much further ado, here comes some text about my In-game Inspector.

Retrieving values from an object

I was going to make my own version of the Unity Inspector and I needed a way to access the values of an object and edit them.
My first step was to create different prefabs for different types such as a float prefab which is just an InputField that I parse to the specific type I want.
To make a Vector3 or 2 prefab, I just copied the first prefab three times and made it look nice.

Now I had to take the relevant values from each Component, which I did by hand. I made a method for each type I wanted to use.
For example I made a method for the Transform type where I created two Vector3 fields for position and scale, and just a float field for the z-rotation.

5d0a8172e8391.png

To know which components to add for each GameObject I made a Dictionary with Types as keys and delegates for values, this way I could control which Components would be displayed in the level editor’s Inspector.
To actually make the values change the object I just used the AddListener method that editable Unity UI Components has to change the actual value when the InputField finished editing.

5d0a8176f07fd.png

These solutions are not optimal since it’s pretty much all manual to setup a new component, so I looked for an automatic solution.
I’m going to say it already, this didn’t work out at all, which will be explained on the way…

I knew how to easily get all the Components from a GameObject.

		
			currentObject.GetComponents<Component>()
		
	

I could also while looping through each of them easily ignore certain Components such as MeshFilter or MeshRenderer which I don’t want the user to access.
There are also ways to access each member of a Type with methods such as GetMember in the Type class.
But that’s where the problems start, when you use that method you get every member of the Type and in Component you have alot of members you don’t want. The ones that are now deprecated (since 2017.2) like the variables camera, collider or rigidBody can easily be distinguished from others since they use the attribute Obsolete.
This is how far I came after tinkering with it in my spare time.
I decided to move on to do other things, sadly, because of the short time frame of the school project.

I will probably go back some day to look more at that problem since it interests me and I have hunch about what the solution could be.
Even with the failures and code I’m not too happy about I do have a working Inspector that just needs some setup. I also did some gameplay code which I’ll maybe mention next time.

5d0a81796ab66.gif

Now this blogpost about Inspecting objects comes to an end and next time you will see more, expect such things as: a transform tool, other objects to use than standard cubes and more components to use in the inspector!

See you next week!



0 comments

Loading...

Next up

This Satuday we invite to watch another #speedpainting of our artist Daniel Faiad.

How great is this scene of #Pecaminosa?

#ScreenShotSaturday | #IndieDev | #DigitalArt

Shoobies leave a sticky trail of mucus in their wake, which can impede movement for any creature that steps in it.

Quantum precognition is one of the most powerful cards. End game cards & equipment. Demo/alpha build boss is no match for this deck.

A Shiny Mega Gengar 🌟 For @ManutkArt 's #ThreeColorsChallenge!

Terraria

Spaaaace~

These are background sprites I've created for a game I'm working on at school ^w^ Click on the post to see how the sprites connect. You won't regret it! (personally, I think it's pretty heheh)

Drawn in Piskel using my mouse. Whaddya think?

My D&D art for my family so far (WIP if you couldn't tell)

Alone Together....

Let me introduce you to the new Mech line: Gendai Spec. Those are Mech that specializes in surprise attacks, covered operations, and stealth. They are equipped with melee weapons but one of Gendai's frames supports sniper rifles.

Cash Banooca