I just started learning Unity/C# and I’m having lot of fun with it However, coming from Scala background, lack of composition/mixin ability in C# feels rather uncomfortable for me.
I tried to see if there’s any viable method to use mixins in C# and found this: Re-mix.
From the description, it seems to be the right tool for my need but I have little idea how I can use it with Unity.
According to “Managed Plugin” section of the Unity manual, I thought I could just drop those dlls somewhere in ‘Assets/…/Plugin/x86’ folder and Unity will update the project setup for me. But it doesn’t add any new references in my Rider (C# IDE I use, as I’m developing on Linux) project, and Unity still complains if I manually add them from the IDE’s side.
As I’m pretty new to Unity/C# stuffs, I might be missing something very obvious. Could anyone tell me what I’m doing wrong, or if is there any viable alternative to use mixins with Unity?
(P.S.: Hope bumping a thread not considered rude here. If so, please let me know. I tried to search ‘bumping’ and all I got was bunch of threads about bump mapping )
Rather than trying to force Unity/C# into a programming model you’re familiar with, I’d recommend putting preconceived notions aside and trying to really grok the way Unity is designed to be used.
It’s based around composition, not inheritance, so many of the problems mix-ins are trying to solve simply don’t arise here.
(However I can’t resist the chance to plug my 2005 Dr. Dobb’s Journal article, “Mixins Without Multiple Inheritance.” That was written for REALbasic, but I think the same trick would work in C#.)
Thanks for the reply! I guess Unity’s ability to allow attaching multiple scripts to the same GameObject could mitigate the problem to a degree, and probably it could be what you meant by “it’s based around composition”, if I’m not mistaken.
I agree that such a feature could be handy, but I hope there could also be a programmatic way to achieve this, because sometimes it’s much more easier to simply add another super type in the inheritance hierarchy than to attach many separate scripts to each GameObjects of the same type.
Maybe I could use a similar approach which is described in your article (it’s a nice read, by the way :)), and I believe C# provides similar extended methods feature, but it’s a bit limited compared to real mixins like implemented in such languages like Scala.
So, I’d like to at least try it, if there could be any alternative to achieve real mixins, and I thought Re-mix could be the right tool for my needs. I’m still curious if there’s any chance it could be used in Unity environment as well, and if it’s possible than what I was doing wrong when I copied its dlls into Assets folder, and etc.)
It seems that I need to make peace with what I have with C#/Unity now. It’s strange how it certainly feels like I can’t do anything without mixins when I had been happy coding Java for more than 15 years
Many of us came from other paradigms and had a hard time feeling comfortable with Unity’s architecture at first. But if you come to it with an open mind and give it some time, I think you’ll find it actually works very well. Write little scripts that each embody just one aspect of behavior, and assemble these onto GameObjects in whatever combination you need. It’s actually pretty darn effective. (And yes, of course you can add components from code too.)