Adding an inspectable custom type

chrisk

Active member
Hi, Justin,

I'm running into a trouble adding my own custom type.
I'm trying to extend a class, for example, ShootableWeapon.cs and add a public custom type, Dictionary in this case, but it won't work.

First of all, I don't want to modify Opsive code directly so that I don't have to do a manual merge everytime I update.

1. Could you please explain how I can add a Dictionary type and make it inspectable? It seems like, in order to display any custom type, I have to add the type to ObjectInspector.cs or something. Is there a way I can add my custom type without touching Opsive file?

1.1 I think the best solution is to make the inspector to display custom type automatically without doing anything, but I'm not sure if you try to do that. One way that I know is to use Odin. I use Odin and Odin has a nice serializer that seems to work for any custom type without any fuss, including Dictionary, however, Odin serializer is not compatible with UCC. It conflicts with UCC and not sure how to replace UCC serializer with Odin's The good news is that Odin provides an open source version of their serializer (https://github.com/TeamSirenix/odin-serializer) and I think it will worth your time to take a look so that adding a custom type will not require any additional work from users, you included. ^^. It's looks really nice if you haven't seen them and it can save you lots of time. I think I heard about that they are even providing a redistributable version of their commercial version. It won't hurt to ask them if you are interested. In the meantime, I wish I could know I to replace UCC serializer with Odin. It will solve my problem until then. ^^



2. I extended a Opsive class and added several primitive property types. And then I created a EditorInspector class on the extended class so that the inspector will display Opsive class in nice format however, my added properties will not show up unless I explicitly list them in GetDrawCallback. Is there a way to display them in the inspector without the explicit listing? It seems like quite a lot of work to maintain both Engine class and Inspector class.

Thanks a lot!

Cheers
 
1. Dictionaries are not serializable in Unity so you have to do a custom inspector if you want to serialize a dictionary.
1.1. I don't think that there will be Odin support anytime soon - it would require too many changes. The preset system generates delegates based on the fields so in a sense I have to serialize everything anyway.

2. Unfortunately not - it does require you to be diligent about keeping GetDrawCallback up to date with the runtime code.
 
Hmm.. I have to say there are good sides of UCC (easy to extend) and bad sides of UCC (hard to extend) at the same time. I like preset system also, but the price to pay for the preset system is bit too high, don't you think? I really hope you can make a bit easier to extend it for programmers. I can't think of doing this for all of my custom types.

1. Odin is an open source and you can perhaps extend your serializer for the preset system. It seems like too much work for us to add a custom type. And requires us to directly modify Opsive code. I think it is very important to make UCC extensible and I hope you take another look. BTW, is there a way to add custom type without modifying Opsive code?

2. If I don't extend the Inspector class, my custom type will show up fine but the Opsive property display is unrecognizable. It seems like there might be way you can display user custom type without the explicit listing, is it impossible? I guess this problem can be solved together if you extend Odin serializer.

I know it is easier said than done but I think it's very important to make UCC extensible, programming-wise. My impression is that you paid lots of attention for artists to make it as extensible as possible but I don't think you really pay the same amount of attention for programmers to extend. I hope something can be done about it.

Cheers!
 
Last edited:
I've written it down on my list to look into adding the ability to add custom types to the serializer without having to change the base class. When Odin serializes it serializes based on the fields whereas the built-in serializes can also recognize properties which is import for the preset system. This is also import for networking - there is a [Snapshot] attribute which isn't used right now but I started to add for server reconciliation/client side prediction for networking. Unfortunately there's just too many custom features required of the serializer to use Odin.

The current serializer does support custom classes/structs without having to extend, but a Dictionary is a special case since Unity doesn't support it.
 
Sure. I can probably give up some conveniences for the sake of networking codes. I wish the very best. I wonder how Odin handles dictionaries and other types that Unity doesn't support. I don't really care if dictionaries are captured by preset system. Would it make it easier to serialize then? or perhaps we can learn something from Odin?? Cheers!
 
Odin would implement custom logic for dictionaries - the serializer that I created for the character controller it follows a features set similar to what Unity's serilizer does. It would definitely be possible to add support for dictionaries, but I didn't have a need for it with any of the objects that I created so that's why it never got added.
 
got it! I know you are under tons of work and having it on your to-do list would be fine for now, along with automatic property listing without having to modify GetDrawCallback. Thanks.
 
Top