Are you ready to start using the SOLID principals in your Unity3D Project? Learn how the Open Closed Principal (the O in SOLID) can make your game easier to develop, extend, and maintain. By using simple interfaces and separating out some code, we’ll convert a solution that’s destined for messiness into a clean and SOLID Unity3D project.
Video
What to Look Out For
Adding new functionality requires you to modify your existing classes
Your class is handling different inputs in different ways to the same method.
You start to see if & else if statements cluttering your code.
Ways to Implement The Open Closed Principal in Unity
Have your classes act on interfaces, not discrete implementations
Use base classes and override their functionality
Add events to your class and have other components on the gameobject register for those events instead of the class calling them directly
The 960 pro is still the top performing SSD available. But make sure your system has an available m2 slot for this special drive.
These come in a variety of sizes and the price jump goes up fast.
If you're looking for a great SSD at a slightly lower price though, go for the 960 EVO (also M.2). The performance specs are very close and the price is about 2/3... I'm grabbing a new 1TB one for myself this holiday season.
If you like tactile feedback, quick response, and awesome color customization like me, the black widow chroma 2 is a perfect fit. The keys use Razers custom green switches, and while they feel great, it's worth noting that they are not quiet 🙂
And if you play games.. when you see the in-game support, be prepared to smile. My favorite is in Overwatch, where the keyboard starts glowing yellow as I heal or blue when I damage boost 🙂
If you read my stuff, you know that I love VR. And while I personally prefer the HTC Vive for my big head and oddly shaped office, the Rift is just as good for 99% of people. And it's priced perfectly for the holidays. Keep an eye out for sales, it's planned to drop to as low as $350 this holiday season.
Update: It's live now for $350 at bestbuy (expecting amazon to pricematch) -
I've been using this microphone personally for about 2 years and love it. Simply plug in the USB port and start talking. The sound quality is great, the price is awesome (often under $100), and it looks great too (get it in just about any color). Definitely a great choice for anyone looking to record podcasts, stream their games, or just chat with their friends online (in-fact my 15yr old just got one for his birthday after his friends kept complaining that his old mic sounded terrible).
If you've been considering getting a digital home assistant like the echo or home, I can't reiterate how awesome they can be. I have mine hooked up to control lights & home entertainment as well (via insteon & the logitech hub).
I also have echos in the house, and while they're a good choice as well, I've been much happier with the way google home understands what I'm asking and answers question. (it'll search and find answers to almost anything I ask)
The Mini version just release too and will be on sale as low as $25. I'm definitely going to pick up a few to spread around the house.
While I love the google home, I also wanted to recommend the Harmony Hub. It works great with both the echo & google ecosystems and can control just about any home entertainment hardware.
I have mine setup to tell google (or alexa) to turn on the TV.. The projector turns on, receiver powers up, switches to the right output, and the lights dim down.
It feels like you're in the future, and doesn't cost much at all... The same goes for shutdown.. no more waiting around, just tell it to shut down and everything turns off.
And of course while I wanted to recommend it, I saw that it now comes bundled with an Echo Dot for about $2 more, well worth the deal. I'd jump on this right away.
Don't have a spare computer to hook up to your TV? Go with a chromecast instead. If you haven't used these, they're awesome..
You can stream straight from your phone (show your screen and share a presentation or game), or using any chromecast enabled app, the device can play video for you. Start a youtube video, hit the chromecast button, and the chromecast takes over, your phone can turn off (or you can use it to control the video).
Sync it up with a google home to say things like "Hey Google, play my favorite youtube channel in the bedroom". I have these on every tv in the house.. and with holiday pricing, expect to see these for around $20.
This last recommendation is the only one I don't own personally... (though I hope to in the near future).
The surface book 2 is a huge upgrade from V1, and if you get the higher end versions, they even include a good GPU capable of running VR games.
The screen pops off to become a tablet, or you can re-connect it for more power (discrete GPU is in there), a quality keyboard, and more battery power.
Finding great art assets for your games is easier today than ever before. Great art can be pretty expensive, but there are quite a few free options available where you can get high quality free 3D models, characters, textures, pbr substances, sound effects, animations, music, environments, vehicles, etc… In this post, I wanted to share a few of my favorites. For each type of asset, I’ve listed my favorite site to get them free.
I recently learned about this site and plugin and it’s amazing. Simply visit the site, find the materials you like, download them and drop them into your project.
There are 100’s of materials for just about anything you could want, and they’re all customizable.
Example
Since these are PBR materials, you can modify them easily (even as a programmer with no artistic skills it’s not tough).
Of all the resources shared here, this is probably my favorite. Mixamo was purchased by Adobe a few years ago and decided to change the pricing structure. All these models & animations were originally for sale at reasonable prices (around $15 per anim), and now they’re all completely free! There are over 50 high quality characters you can use in your games, and 1000’s of animations.
On top of all the free stuff they provide, the mixamo system will automatically retarget their animations for your other characters. You can bring characters that you’ve modeled, purchased, or found free in other places right into the site, apply the animations of your choice, and start using them in your game.
This site has a nice variety of assets available. There are great 2D sprites, free 3D models, music, sounds, textures, fonts, and even text files full of character names you can use.
It’s also my favorite source for free sound effects & 2D art assets.
Of course every Unity developer should be utilizing the asset store. And while I spend a lot of $$$ on assets, there are also a ton of free assets. There are over 1509 free models alone!
This is also the best place for free particle systems, none of the competitors come close. Of course like OpenGameArt, there are a ton of free 3d models, 2d sprites, and everything on the asset store.
Conclusions
Again a lot of these sites have more than I mentioned, but I wanted to focus on the areas where they stand out above the competition. I’m also always looking for more great resources, so if you have some to recommend, please drop a comment below.
I’ve been playing with the new Unity3D Machine Learning system for a few days now and made a little progress. I wanted to share the steps I found to get a newly created agent setup and trained to complete a basic task. In this post, you’ll see how to setup a basic agent with the goal of reaching a randomly chosen number using nothing but reinforced machine learning. We’ll use the new Unity ML Agent system and tensorflow to create and train the agent to complete the task and discuss ways to extend this into a real game AI.
Once you’ve gone through that process, open the Unity project and create a new scene.
The first thing we need is an academy. Create a new gameobject, name it “NumberAcademy“.
Add the “TemplateAcademy” component to the “NumberAcademy“. Our setup doesn’t need the academy to do anything special, so we can start with the basic blank academy provided in the template.
Under the Academy, create another child gameobject. Name it “NumberBrain“.
Add a Brain component to it.
Set the State & Action size variables to 2.
Set the Action Space Type to Discrete. We’ll be using 2 discrete actions (up or down) in our project. We use discrete because these are represented as integers.
Set the State Space type to Continuous. We’ll be tracking two floats, for state, so we use continuous.
Set the Brain Type to “Player”
Add 2 actions. Choose any 2 keys you want (I went with A & B), but set the Values to 0 and 1. The key bound to value 0 decrements the #, the key bound to 1 will increment it.
The NumberDemoAgent Script
Create a new script named NumberDemoAgent.cs
Set the base class to Agent (replace the : MonoBehaviour with : Agent)
Add the following fields:
The currentNumber and targetNumber fields are the most important here. Everything else is just for debugging and visualizing.
Our agent will pick a random targetNumber and try to get the currentNumber to our target using our increment and decrement commands.
Next we need to override the CollectState method like this:
Here, we’re returning our two floats for current and target number as the state of our agent. Notice how this matches up with our 2 state variables on the brain and they’re floats which is why we have it set to continuous state instead of discrete.
For our agent to train, we need to select random target numbers. To do that, we’ll override the AgentReset() method like this:
The final and most important part we need is the AgentStep() method. This is where we take in actions (aka input), perform some tasks (respond to the actions), and reward our agent for successful choices.
The first thing you’ll see is our text update. This is only for debugging / visualizing. It allows us to see the current #, the target, and the # of times we’ve successfully solved the problem (reached the target number).
Next up is the switch where we look at the action and perform our task. In this case, we either respond to action 0 by decrementing the current number, or to action 1 by incrementing it. Any value out of that shouldn’t happen, but if we get one, we just ignore it and return.
Then we move our cube based on the currentNumber (using it for the x offset). This cube again is only for visualizing, it has no impact on the actual logic or training.
We then check the currentNumber against some known limits. Since we choose a random number between -1 & 1, if we reach -1.2 or +1.2, we can consider it a failure as it’s definitely going in the wrong direction. In that case, we set the reward to -1 to denote a failure, then mark done as true so the agent can reset and try again.
Then finally, we check to see if the currentNumber is within 0.01 of the target. If so, we consider that a match, set the reward to 1.0 for a success, and mark it as done. We also increment the solved counter for debugging purposes (it’s nice to see how many times it’s been successful).
Here’s the complete script:
Setup The Agent
With the script ready, we need to create a new gameobject and name it “NumberDemoAgent”.
Attach the NumberDemoAgent script to it and assign the brain.
Next create a Text object and place it where you can see it (ideally big in the middle of the screen).
Assign the text object to the NumberDemoAgent.
Create a Cube and a Sphere and assign them to the NumberDemoAgent as well (these will help you see what’s going on, much easier than reading #s).
Testing in Player Mode
Now press play. You should be able to move the cube left and right with your two hotkeys (remember I went with A & B for the hotkeys).
When you get the box to the sphere, it should increment the solved count and reset. If you go too far the wrong way it should also reset (remember that 1.2 limit).
Training
Once it works in player mode, select the brain and change the “Brain Type” to “External”
Save your scene and build an executable where the scene is the only thing included (with debug mode enabled).
For your output folder, choose the python subdirectory of your ml-agents project (included when you downloaded or cloned the source project). For example, mine is located here: C:\ml-agents\python.
Remember the name you give it, you’ll need that in just a minute.
Anaconda / Jupyter
Launch an anaconda prompt.
Change directory to the python folder you just built into. ex. “cd c:\ml-agents\python”
Enter the command “jupyter notebook” (you may need to hit enter a 2nd time btw)
You should be prompted with a web interface shortly after that looks like this:
Change the highlighted parts to match. On the env_name, don’t just put in “numberdemo”, use the name that you built your executable with. Buffer_size and batch_size you can copy though (it’s important to note that these #’s were only found by testing/trying, even after getting it working, I still barely understand what’s going on with them).
Once you’re done editing the hyperparameters, run the steps in order.
Start with step 1 & 2. (the * disappears and a # appears in the [*] when it’s done.
When you run step 3, you should see a window appear for your game (a small window though). The first time, you’ll probably also get a windows permissions dialog, make sure to allow it.
Once you start step 4… WAIT.. and watch the results come in (first one may take a minute so be patient)
Once it’s saved a couple times, hit the stop button. Then move on to step 5 and run it. This will export your training data to a .bytes file in the “python/models/ppo” subfolder.
Copy the .bytes file (again it’ll be named to match your executable name) and place it in your Unity project somewhere.
Select the brain and set the “Brain Type” to “Internal”.
Assign the .bytes file to the “Graph Model” field.
Save and press play!
Conclusions
This is a pretty simple sample, meant to just help get a basic understanding how how this system works. I’m excited to see where it goes though and build bigger more interesting projects to control game AI and make interesting gameplay / bots.
I’m extremely excited about the new Unity3D Machine Learning functionality that’s being added. Setting it up was a little painful though, so I wanted to share the steps I followed, with the specific versions that work (I tried a whole lot and nothing else worked). In this guide, I’ll show you everything you need to get setup and ready to start with the 3D ball example. There’s also a video version at the end..
Installing the CUDA toolkit
You’ll need to download CUDA 8.0.61 for this to work.
You can view the CUDA download archive here: https://developer.nvidia.com/cuda-toolkit-archive
One issue I ran into though was the ENABLE_TENSORFLOW define being cleared out after I installed the tensorflowsharp library. When this happened, the “Internal” option disappeared. Simply re-add it and hit play so it re-compiles, then the internal option should re-appear.
Special Thanks
First I wanted to say thanks to the guys at Unity for building this all out. I’m excited to start integrating machine learning into projects for my AI.
I also wanted to thank Nitish Mutha for this awesome blog post that got me 90% of the way through this setup.
Scaling a player in VR opens up a world of options for game design and can be a ton of fun. In this example, I’ll show you how to quickly adjust the scale of your player, make them shrink and grow at will with a couple lines of c# in your Unity3D project. We’ll use SteamVR and the CameraRig to make our player tiny, walk through a little door they couldn’t normally get into, then scale them back up on the other side. Recreate it yourself or download the project sample.
This is a simple system I’ve used to pass soccer balls, hockey pucks, and anything else you can imagine in a sports game from one player to another. The passing script contains everything needed to make something like this work and the logic for calculating the closest angle to your aim is pretty straightforward (and included in the project source below)
Build your own snap to grid system in minutes with this project as a starting point or sample. You can create a Unity3D Grid based game easily by creating a single component responsible for giving your project the correct grid coordinates.
This basic grid system works by taking in a vector3 and providing the nearest point on the grid to that position. Your code only needs to call into the Grid class to get that location, with no other modifications. The grid can be resized or offset by simply moving it around in the scene, and you can visualize the layout using OnDrawGizmos as seen in the video.
C# delegates and events are extremely powerful and understanding them will make your life as a Unity developer much easier. Luckily, they’re pretty easy to learn and you can start incorporating them in your projects today. In this 2 part post, I cover the basics of delegates and how they work, then lead into how you can use delegates as callbacks for your coroutines. With this technique, you can launch a coroutine that can perform whatever action(s) you choose when it’s done, all in a clean and reusable manner.
Part 1 – Delegate Basics (4 mins)
Part 2 – Delegates as Callbacks for Coroutines (4 mins)
Conclusions
Using delegates can make your project clean and extensible, removing the need for endless if statements, switches, etc.