generic and inheritance
https://paste.mod.gg/fgpktwfizvwd/0
@Aaron its unity but i suppose its really doesnt matter right?
BlazeBin - fgpktwfizvwd
A tool for sharing your source code with the world!
26 Replies
i want the children of entity have its corresponding config
okay you probably do not want your code to use inheritance like this
whats your experience dealing this scenario
well what probably are you trying to solve with inheritance here
i want the children of entity have its corresponding config
and entity can have the entity config
Try to make a global scriptable object class for both enemies and heroes you can use instead of using too much inheritance, or use a separate one for enemy and one for hero without the inheritance
It can easily become a mess if you use too much inheritance
a global scriptable object? not sure i understand
One that you can use on both heroes and enemies
nonetheless, what exactly isn't working?
doesnt compile atm
public abstract class Entity<TConfig> : Entity where TConfig : EntityConfigSO<Entity>
public abstract class Entity : MonoBehaviour
like this ?
the non generic entity can be used on both i guess
What properties would differ from Hero and Monster?
right now just upgrades it can have, but i certainly it gonna have more fr
monster also have its spawn data thing in the config
So, I would suggest to make the upgrades scriptable objects instead of messing with generics / inheritance which may cause problems reading and understanding the code and also adds complexity.
monster doesnt have upgrade
and hero doesnt spawn
you mean i should i throw all into entity config ?
If possible, yes.
its possible yes one big class fr
dont know if its right, so im just seperating them out atm
custom inspectors are powerful, you can use that.
but the class still have leftover instances right
Scriptable objects can have sub-scriptable objects.
You can make it farily modular with scriptable objects, that way if you have designers they won't have to touch any code.
Such as:

and I use no generics for that, I do however use some inheritance.
But most of its functionality comes from the custom inspector
your Mage there, does it hold the prefab, and does this inherit from entity thing too
It holds the scriptable object, yes. I use no inheritance for that.
However, your system if you get it working might be really good but as mentioned, it adds complexity.
so your mage, warrior,... and mosnter are seprate class
no inherit at all? im not sure that sound right
no? for common stuff like take damage, move, changing states,...
how did you combat this
What do you mean?
For taking damage I have an interface called IDamageable and a class called UnitHealth that inherits from MonoBehaviour and implements the IDamageable interface and a function to load the data from a scriptable object, no need to make separate classes for such things as they are all entities that should take damage, right?
However, I see why you want to do it like that, you can have an interface or a base class you inherit from which uses no generics.
ok both of you suggest me to remove the strcture
i will give this the last try today and ditch it
have to go work atm fr thanks
gonna big ah class instead fr it is what it is
If you removed Entity's type argument, it might work as you want it to and use an interface as the Config
But I doubt Unity will serialize that
Which is where a custom inspector comes in and helps
as currently all your types requires a type argument
Or at least both the abstract classes do
It might work if you just put EntityConfigSO in Config
Nope, nevermind that is also dependant on generics