- Home /
Indent or resize entire components in custom inspector
Hello!
Now I'm not sure if this is even possible, after what feels like a ton of googling I can't come up with any answers so I'm asking the question here instead. I have made a component-based hierarchial state-machine in unity and got it to work pretty well. Unfortunately I do have the knowledge for how to make a node-based Editor in Unity and can't really find any tutorials that are free and looks good so I have for now settled with having the ftm in the inspector.
The problem I am trying to solve right now is if it is possible to indent entire components, each state in my state machine is a component, and what I would like to to do in my custom inspector is to indent each state that is a substate to another, thereby creating a nice hiearchy where you can clearly see state and substates in the editor. Although I'm not finding any way to actually controll the component widht, height or even indention level. So I am wondering if this is even possible, if it is not, does anyone at least know a way to get the position of an component in the inspector so I can insert color-based rects to tell which state belong to eachother.
Grateful for any answers, and I apologise for the tl;dr.
Best, Simon
EDIT: Here's a image of kind of what I am looking for, sorry if I confused anyone.
Answer by gameplay4all · Feb 22, 2017 at 03:09 PM
https://docs.unity3d.com/ScriptReference/EditorGUI-indentLevel.html
EditorGUI.indentLevel
Should do the trick if you are using GUILayout. :)
-Gameplay4all
Hello and thank you for answering!
Unfortunately this was not exactly what I was looking for, I was looking to indent the entire component "window" so that the component would visusally be further into to the inspector than another component, I know this is also an awful explanation of the problem but I added a image of how I would kind of like it to be in the original post.
If you indeed did mean that it would be able to do what was intended in the image then it must be my implementation that is wrong with and I will look further into it under such circumstances.
Ah, okay. Well that would be hard to pull off, if not impossible. You can write custom inspectors for every component your system is using so you can at least indent all the fields and remove the "script" field. But I am pretty sure you can't indent component headers. I am of no further help here I'm afraid :( Good luck!
Answer by RobAnthem · Feb 22, 2017 at 06:37 PM
If you are doing a recursion, then I might suggest something like this.
void IterateStates(State state)
{
if (state.States != null)
{
foreach (State enemyState in state.States )
{
if (enemyState != null)
{
EditorGUILayout.BeginHorizontal();
GUILayout.Space(15 * stateHierarchy);
EditorGUILayout.ObjectField(enemyState, typeof(State), false);
EditorGUILayout.EndHorizontal();
stateHierarchy++;
IterateStates(enemyState );
stateHierarchy--;
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612111714im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Questions Regarding Images in Custom Inspector/Editor 1 Answer
Creating enum using a string array 3 Answers
Reorderable list of UnityEvents 2 Answers
Make a custom inspector that shows a group of variables in form of list 2 Answers
How do I change inspector values of other game objects using a custom Editor Window 0 Answers