I have a daily system where our AI can path towards a certain area, up from there i want my AI to perform a custom action.
im currently doing so with ScriptableObjects which after “Start” create a custom “Class” as a class-based action. It works but it is not suitable for loads of AI since i will have to create for each daily action an SO since not all AI is doing the same, i have to add some custom fields and fill them out.
I have seen that Cinemachine is doing something interessting, they have certain dropdowns which enable/disable fields based on the developers needs. Would that be a way? I assume they have an “Enum” for certain occasions and depending on the Enums value, they enable/disable fields in the inspector ?
What do you mean by enable/disable fields? Do you mean that certain fields are only visible based on the dropdown? If so, you can make your own PropertyDrawer to do something like that.
Yes, something similar to this example.
i will see if it is suitable for me
I mean, having a dropdown of Serializable Classes, on select i can see their properties and fill them out.
Depending on which class from the dropdown i select, i see its properties as usually i would if i would have a public class declared in a public or Serialized variable.
that’s a custom editor. you want one property to affect visibility of the others.
to do this you need to create a custom editor, and that’s a load of work if you’re a rookie.
you could perhaps get away with something simpler, but you’d still have to understand how IMGUI editors work, at the very least.
with properties being enabled/disabled, something similar is going on, it’s just you don’t skip to draw them, but instead you fix GUI.enabled to a setting you wish to apply to any control that comes after it. so it becomes tricky to write this code naively, because it clutters too easily with all kinds of nonsense.
however, there is a middle ground for you. go look for naughty attributes on the github (here’s a link), you’ll find a custom attributes library intended for quickly hinting the MonoBehaviour fields to enable a relatively responsive interface. search for EnableIf where you can use a conditional to arbitrarily toggle things based on user expressions. very easy to use, very complicated to customize, but it has a load of features ready to go. maybe it’s perfect for you.
btw if you want to learn how to make drawers, and you like to read/learn, you can also check out this guide I made about a custom enumeration type that I then integrated with the unity inspectors.
Have done that approach but not sure if that is the right way todo it.
I mean, hiding attributes/fields is a “ok” thing but not what i really want, would love to dynamically decide on which action(c# class) i choose and fill out its variables in the inspector.
If that doesnt work out, i would assume, i will have to initialize it via code as it is done native.
then you would have to dynamically type in some code. there is no easy way out.
the best part about the custom inspectors is that you have the absolute control about how they look and work.
the worst part about anything custom in unity is that you kind of have the absolute control about how everything looks and works. this includes the mundane stuff and almost zero documentation. my best documentation in this field is my own prior work. if we add everything together I’ve lost several years just by researching editors and backend customization.
yes they’re making certain things more accessible with uielements, but I’m afraid this will all just explode into multi-tiered studio work, like web technologies, where a single programmer, enthusiast, or even octopus won’t have enough arms to fully grasp everything that the system offers and demands in order to be customized.
unity should’ve become more approachable and customizable, to foster creativity and productivity of an individual, but instead it is constantly re-orienting itself toward the little sweatshops that constitute its ecosystem. there is no profit in the individual being productive, you really want a small-to-medium fully licensed studio to provide exactly these services and assets to individuals, who then browse for goods like a customer would in a shopping mall.
and so that’s how things work if you want a tool that speeds you up. you either invest your time in it, or you end up investing bucks in it. this lost time is what drives the prices, after all.
This is a situation where I’d just use my best friend SerializeReference and serialise a collection of either base class or interface implementing plain classes.
Unity doesn’t fully support drawing SerializeReference fields, so you’d either need to make a custom inspector for it to work, but there’s plenty of free or paid addons (such as Odin) that make it work out of the box.
This the sort of design I do on a daily basis now.
You’re welcome. I wish I had some more time to spare, to show you an example editor, but it’s a lot of tedious work atm and I’m a little tired. The ones I readily use are too complicated, because I’m building upon a years-old foundation, and this would only intimidate you to the point of PTSD.
It’s not really that hard, just tedious. But in the end, you want to be as speedy as possible. Good intentions only take you so far, but being cost-effective with your time is what matters the most.