00:00
00:00
MonoFlauta
Indie Game Developer + Senior Software Engineer @ Etermax

Facundo Balboa @MonoFlauta

Age 31

Indie Game Developer

Escuela Da Vinci

Buenos Aires, Argentina

Joined on 7/30/08

Level:
27
Exp Points:
7,866 / 8,090
Exp Rank:
5,253
Vote Power:
6.87 votes
Rank:
Police Sergeant
Global Rank:
9,164
Blams:
214
Saves:
823
B/P Bonus:
12%
Whistle:
Bronze
Trophies:
15
Medals:
773
Supporter:
8y 3d

Comments

It's cool seeing programming advice making it's way into NG. Keep up the great work :D

Thank you!

This is a very comprehensive writeup! You might want to post it in the game dev forum as well, for those who may start off using Unity there.

Would another way for MonoBehaviours to communicate with each other involve dispatching events? I haven't used Unity, but I've done something similar in Flash where one object would dispatch an event that only a specific class of objects was listening for (of which there would be only one instance thereof), so it would effectively be like the two objects communicating directly with each other without knowing about the other's presence. I believe that an event dispatching system exists in Unity (or it could be faked with a singleton if required), so where would an equivalent method figure in this list?

First of all, thank you for reading! I appreciate you took the time to leave a comment :)
I think you are right. That is another way of communication between MonoBehaviours. I think I didn't think about it because it isn't a direct communication between them, you actually talk through events and you hope for the other part to just listen to it, but it is still a good and a really useful example!
Unity has a system of events but I always preferred to make my ones. A long time ago I used this one I made: https://github.com/MonoFlauta/Framework-Goat/tree/master/FrameworkGoat/EventManager
But now I just use UniRx (https://github.com/neuecc/UniRx) because I believe it is a lot more powerful and I just use it a lot at my work :P
Anyway, thank you once again for reading :)

I find myself using singletons very often. Maybe I'm spawning enemies on the fly and they need a reference to Player, but I don't want to assign their reference to player every time one is spawned in. Singleton.

It works but it feels yucky somehow.

Maybe you could save the reference of the player in the spawner. That way every time you spawn an enemy you can maybe call a method like:
void Init(Player player)
And they could save it there. That way you could avoid the singleton.
Anyway, it is not a bad thing if it works for you :)
Thank you for reading!

@MonoFlauta to be fair, I suppose you technically DID include it - an event based messaging system is just a fancy Singleton, haha :P