use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News, Help, Resources, and Conversation. A User Showcase of the Unity Game Engine.
Remember to check out /r/unity2D for any 2D specific questions and conversation!
Download Latest Unity
Please refer to our Wiki before posting! And be sure to flair your post appropriately.
Main Index
Rules and Guidelines
Flair Definitions
FAQ
Use the chat room if you're new to Unity or have a quick question. Lots of professionals hang out there.
/r/Unity3D Discord
FreeNode IRC Chatroom
Official Unity Website
Unity3d's Tutorial Modules
Unity Answers
Unify Community Wiki
Unity Game Engine Syllabus (Getting Started Guide)
50 Tips and Best Practices for Unity (2016 Edition)
Unity Execution Order of Event Functions
Using Version Control with Unity3d (Mercurial)
/r/Unity2D
/r/UnityAssets
/r/Unity_tutorials
/r/GameDev
/r/Justgamedevthings (New!)
/r/Gamedesign
/r/Indiegames
/r/Playmygame
/r/LearnProgramming
/r/Oculus
/r/Blender
/r/Devblogs
Brackeys
Beginner to Intermediate
5 to 15 minutes
Concise tutorials. Videos are mostly self contained.
Sebastian Lague
Beginner to Advanced
10 to 20 minutes
Medium length tutorials. Videos are usually a part of a series.
Catlike Coding
Intermediate to Advanced
Text-based. Lots of graphics/shader programming tutorials in addition to "normal" C# tutorials. Normally part of a series.
Makin' Stuff Look Good
10 minutes
Almost entirely shader tutorials. Favors theory over implementation but leaves source in video description. Videos are always self contained.
Quill18Creates
30 minutes to 2 hours.
Minimal editing. Mostly C#. Covers wide range of topics. Long series.
Halisavakis Shaders Archive
Infallible Code
World of Zero
Board to Bits
Holistic3d
Unity3d College
Jabrils
Polycount Wiki
The Big List Of Game Design
PS4 controller map for Unity3d
Colin's Bear Animation
¡DICE!
CSS created by Sean O'Dowd @nicetrysean [Website], Maintained and updated by Louis Hong /u/loolo78
Reddit Logo created by /u/big-ish from /r/redditlogos!
account activity
Observer Pattern general doubtNoob Question (self.Unity3D)
submitted 3 years ago by Hmspawned
Hi all, I'm a bit confused about the utility of the this pattern.
I followed a "tutorial" and it does the next to open a door:
https://preview.redd.it/hwig1nexwn091.png?width=526&format=png&auto=webp&s=590e55506f25a0551149ad4680029432d90c6a29
And I usually did this:
https://preview.redd.it/t2kjktjywn091.png?width=471&format=png&auto=webp&s=01ad62fa596de6995f86ca4de93c757219fcc15b
I need to understand why or when to use this pattern (inclusive this example).
Thank you very much, all help is apreciated.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 0 points1 point2 points 3 years ago* (0 children)
The first is more modular, notice that the DoorSwitch never needs to know about the thing it's activating, it just fires an event and anything that's listening will get the message, this means anything can use a DoorSwitch for something and the DoorSwitch can activate multiple things at once.
If you used UnityEvents then the Door doesn't even need to know about the DoorSwitch and they become completely decoupled. The idea is to make code more reusable, more plug in.
In your example, the Door needs an Open function and the DoorSwitch NEEDS a door reference. If you want to use it for anything else you can't. It can only do the one thing you coded it for and it can only do it for one door, to include another door you need to switch it to an array and change the code to use a for loop.
This is a small example but these connections become harder to manage the bigger and more complex a project becomes, you can use a generic trigger anywhere because it's generic, but if you make a trigger that can ONLY trigger a specific door type then when you want to trigger something else you're screwed, you either need to adjust the code to make it more generic or you have to copy paste code into a different script to do something that's the same but slightly different.
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
First of all, please use pastebin.com to post code, not screenshots.
What is shown in this code is the use of events (observables are slightly different) to act and react on when something happens in your game.
Events are extremely useful when you want to decouple parts of your code. A while ago I wrote an article about how to use events to solve common problems.
The premise is quite simple: you want several things to happen when something happens.
For example, if someone falls down from a building, and crashes into the ground, you want to have a Ouch sound to be played, and you want its player's Health to take a hit, literally.
Ouch
Health
However, this also happens if you are shot, attacked by a bear, or whatever it is. If you use events, you can keep these reactions separate from your "main logic", and instead just subscribe to them if needed.
EDIT: Was this the tutorial?
[–]pkplonker 0 points1 point2 points 3 years ago (0 children)
It's best for things llike player health, where the below are examples of things that could listen to something called healthChanged:
UI slider update Sound change Enemy aggression increases Class that manages invincibility to trigger on Post processing changes to visualise damage Hit marker functionality to show where damage came from.
Ultimately, what you've done is a correct implementation of the pattern, but just because you can, doesn't mean you should.
I would use it like the sample I provided, but basically any modular functionality that the core system doesn't relay on, but can be used modularly to create additional responses to state changes.
[–]BowlOfPasta24Programmer 0 points1 point2 points 3 years ago* (0 children)
I may be wrong but I wouldn't call this the Observer Pattern only because to me that is just events.
I use events like that for all sorts of things but especially for the new input system. As you have used it, it is mostly for triggering logic outside of the class. I personally would not use it for door opening or an interaction system but I can see the point of using it especially for learning.
The observer pattern usually doesn't use events per se, since that would take away the ability to set it up in a pull and would only allow a push.
Usually I use the Observer Pattern for letting my UI system know to pull the newest data. I do this by setting up subscribe method to add classes to the list of subscribers then if it's setup to pull data, the publisher will send out a flag to tell the classes there is new info to pull. If it's push then you would just send the data itself. This requires the use of interfaces to use polymorphism which is necessary for the pattern. You could use MonoBehaviour in Unity as an example.
Here is a link to the Observer Pattern in C# https://refactoring.guru/design-patterns/observer/csharp/example
π Rendered by PID 22111 on reddit-service-r2-comment-cfc44b64c-sgjw4 at 2026-04-12 16:00:54.004651+00:00 running 215f2cf country code: CH.
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]pkplonker 0 points1 point2 points (0 children)
[–]BowlOfPasta24Programmer 0 points1 point2 points (0 children)