I'm Sam Wronski a software engineer specializing in mobile and game development. Most of this is my exploration of various technologies both old and new. I also run a YouTube channel and record a lot of my work. Hopefully it's educational. Failing that, hopefully it's entertaining. Read more...
Don't wanna be here? Send us removal request.
Video
youtube
With the Scriptable Render Pipeline in Unity 2019 a new post-processing concept has been introduced. This allows you to define `Volumes` which apply a set of effects across the scene or to a particular portion of the screen. For example changing the amount of saturation, white-balance or bloom to emphasize different parts of the environment. Unity Scene's in the HDRP (High Definition Render Pipeline) have Volumes by default. These are used to define global default post-processing effects and are done by setting the `IsGlobal` flag of the `Volume` to `true`. We can start having a lot of fun when we disable that flag on our own custom `Volume`s. To get started with this, you'll need to create a new `GameObject` and add a `Volume` component to it. Disable the `IsGlobal` option to create a localized post-processing effect. Next add a second component to the game object that is a Collider which represents the volume you want to apply the effect in (I don't show this, but you probably want to set this Collider to be a Trigger to avoid randomly colliding with your effects 😅). Once this collider is added the warning to add a collider should disappear - local post-processing effects will not work if you do not define a collider to provide the area of effect. Now that we have an area defined for our Post Processing Effects add an existing Volume Profile or create a new Profile (this will create a new Asset under your base `Assets/` directory - you probably want to move it somewhere else). Once you have the profile, modify the settings to match the effect you are hoping to achieve by adding or removing Overrides. These override the default render settings of the scene with the values you provide. Disabling the settings in the menu will defer the value to the existing defaults. After the Profile is configured you should see your effects applied as soon as the camera is moved into the Collider you defined originally. If you would like the transition to be smoother between the effects you may also add some amount of blending. This pads the area outside the area you defined and applies a portion of the effect you configured based on how close to the effect Volume the camera is. If you do not want to move your camera around to test each of your Volume's you can also toggle the `IsGlobal` flag to temporarily apply the effect globally. Unity has documented these Volume Overrides more on their GitHub page. Check that out here: http://bit.ly/2HKmGS5 Join the World of Zero Discord Server: http://bit.ly/2txCKO8
0 notes
Video
youtube
I've been experimenting with creating custom Inspectors and Editor Windows in Unity lately and one of the features I've found is the `GenericMenu` class. This allows you to create Drop Down and Context Menu's in Unity. To draw a Context Menu with two options (Foo and Bar) which will print themselves to the Unity Console when clicked the code might look something like this: ```csharp // Create a new Generic Menu object var menu = new GenericMenu(); // Create a reusable function for the menu options var function = new GenericMenu.MenuFunction2((name) ⇒ { Debug.Log($"{name}"); }); // Create two new menu options to print foo and bar menu.AddItem(new GUIContent("Print Foo"), false, function, "Foo"); menu.AddItem(new GUIContent("Print Bar"), false, function, "Bar"); // Display the context menu menu.ShowAsContext(); ``` The documentation for `GenericMenu` is also on Unity's scripting references with additional examples: http://bit.ly/2HikBwj Join the World of Zero Discord Server: http://bit.ly/2txCKO8
0 notes
Video
youtube
There are a few fun ways to make fantastic Editor tools in Unity for your code. Two of those are `Handles` and `GenericMenu`. They enable you to create interactive components inside the Unity Scene View that allow you to more easily interact with your objects. They work as fantastic solutions for building custom editors. The thing is... I've never really used them. It's time that changed. Lets explore how these features work and how we might use them for our own projects. How do we draw a custom Handle using Unity's Handle features? How about creating a custom editor with a context menu we can consume? We'll build both to improve the visualization of our custom Graph code from a previous video. To draw a basic `Handle` you may use `OnSceneGUI`. A sample of what this kind of editor might look like is below. It will draw a yellow line from the center of the scene to the `GameObject`'s position. ```csharp using UnityEditor; [CustomEditor(typeof(MyCustomClass))] public class MyCustomClassEditor: Editor { protected virtual void OnSceneGUI() { MyCustomClass customClass = (MyCustomClass)target; // Safety against selecting a null GameObject if (customClass == null) { return; } Handles.color = Color.yellow; Handles.DrawLine(Vector3.one, customClass.transform.position); } } ``` You may draw a custom `GenericMenu` using something like this. It will create a two option menu that prints out the selected option to the Debug Log. ```csharp GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("The name of a menu option"), false, () ⇒ { Debug.Log("Picked First Option"); }); menu.AddItem(new GUIContent("The name of a second menu option"), false, () ⇒ { Debug.Log("Picked Second Option"); }); // once you are done, show your menu menu.ShowAsContext(); ``` The documentation for `Handles` is available on Unity's website: http://bit.ly/2mbizFt The documentation for `GenericMenu` is also on Unity's site. More info here: http://bit.ly/2HikBwj Join the World of Zero Discord Server: http://bit.ly/2txCKO8
0 notes
Video
youtube
Unity makes it possible to draw simple debugging information in your scene and even in-game while using the Unity Editor using Gizmos. Gizmos can be used to visualize many different things and allow you to render Cubes, Spheres, Lines and more. This is great if you want to mark points of interest, plot out your objects pathfinding or show the trajectory of projectiles in your game. The options are entirely up to you! To add Gizmos to a `MonoBehavior` you can add an `OnDrawGizmos` function to the `MonoBehavior`. An example might look like this to draw a unique marker at the position of every `GameObject` with the `MonoBehavior` attached to it. ```csharp void OnDrawGizmos() { Gizmos.color = Color.blue; Gizmos.DrawSphere(transform.position, 1); Gizmos.color = Color.white; Gizmos.DrawWireSphere(transform.position, 1.1f); } ``` Gizmos will draw through most objects in the scene so they can be seen even when normal objects would be occluded by other objects. By default `OnDrawGizmos` will always draw. However if you would like to draw Gizmos only when the object is selected in the Editor you may use `OnDrawGizmosSelected` in place of `OnDrawGizmos`. This functions the same way as `OnDrawGizmos` but is only called when you have selected the object. One use for `OnDrawGizmosSelected` can be to change the color of the drawn object for selected objects. This code draws selected objects in white, and others in red: ```csharp void OnDrawGizmos() { Gizmos.color = Color.red; Gizmos.DrawSphere(transform.position, 1); } // Invoked if Gizmos are enabled and the object is selected void OnDrawGizmosSelected() { Gizmos.color = Color.white; Gizmos.DrawSphere(transform.position, 1); } ``` More information about the functions available for drawing Gizmos in Unity: http://bit.ly/2mDx55a Join the World of Zero Discord Server: http://bit.ly/2txCKO8
0 notes
Video
youtube
I've been trying to replace the old World of Zero website for a while now. A beta of the new version is finally in a working state and I'd love for you all to check it out! The previous worldofzero.com is run off of Tumblr and the experience... isn't great. The content for that site is uploaded automatically via a robot that detects new YouTube uploads. The problem with this pipeline is things like formatting are completely removed. Additionally links are replaced with bit.ly versions. Overall it's not a great user experience, especially with how slow the entire site is in general. The new site is built from scratch in React using [Next.JS](https://nextjs.org/). This gives us a bit more freedom to build something fast and responsive with a more suited UI. The backend is a custom ASP.NET server which makes calls to the YouTube API services to retrieve videos. There's a few fun new features I've added here as well that I'm excited to expand on in the future. 1. The descriptions support Markdown! This means that we get very pretty descriptions and... 2. Syntax Highlighting! As part of the Markdown support we also are able to add syntax highlighting so languages are displayed in what I hope is a very readable way. Three examples of this are csharp, java and shader highlighting: ```csharp var test = "Hello, beta.worldofzero.com!"; ``` ```java String test = "Hello, beta.worldofzero.com!"; ``` ```shader float3 = float3(42.0, 9001.0, 3.14159); ``` All languages are distinguished by a unique color and a link to Learn More which I've tried to link to an online sandbox for that language (try.dot.net in the case of C# and shadertoy.com in the case of shaders). This feature is pretty experimental at this point so I'd love to hear your feedback on it! There are a lot of ways we could improve this more and I'd love to get your feedback on what works, what could use more work and cool new features you think would make it even better! You can checkout the new World of Zero website at http://bit.ly/2Gvh8cl while it's in testing. If you want to checkout the code for this new website you can head to: http://bit.ly/2UPeR5H. Join the World of Zero Discord Server: http://bit.ly/2txCKO8
0 notes
Video
youtube
Matrices are an extremely powerful tool when working with vectors. They're the magic that makes a lot of the code in our shaders work, but they also work in a lot of handy other places. For this video we're going to look into using a matrix to rotate a ring of vectors around a single point. This will allow us to simulate an asteroid ring or something else as we want. To do this we'll generate a list of vectors (using some sin and cosine stuff to make them a circle). Once we have that list of vectors we can multiply them by a rotation matrix every frame to slowly rotate the points in a circle. That's really it. It's not a complex project, but it's a handy experiment. The goal here is to be able to create a large scale asteroid belt by using these matrices as a force on the asteroids instead of manually applying force to each individual asteroid. * It's also a fun way to play with matrices 😁 * The way we're using Matrices in this example is effectively how a parented `GameObject` works in Unity by applying it's own matrix (it's transform) to its children. The main difference is that our solution does not require additional `GameObject`s or other Unity specific features. It's just math. Join the World of Zero Discord Server: http://bit.ly/2txCKO8
0 notes
Video
youtube
Unity provides a funtion that allows your MonoBehaviors to be alerted when values are changed on it in the inspector. The `OnValidate` method is invoked every time you modify a value in the inspector (only the inspector, changes to the value via code don't publish any alerts). This makes it possible to validate your modifications in a way that makes sense. In our example we'll use a min and max value where the min/max function as limits on one another so the min value can't exceed the max value. An example that logs a notification every time you modify the value might look like this: ```csharp public void OnValidate() { Debug.Log("The Unity Inspector Has Detected an Update"); } ``` Join the World of Zero Discord Server: http://bit.ly/2txCKO8
0 notes
Video
youtube
Lets explore this new health tracking component we've built by introducing the Unity Test Runner to our project. The Unity Test Runner allows you to add a variety of NUnit tests to your project that allow you to create Edit and Play mode tests. In this video our goal is to build a testing system that is able to validate all the capabilities of the `HealthTrackingComponent` we have. This is my journey learning and implementing tests on the project. I've identified 3 main features we'll want to place under test: - That the value of our health can be changed. - That the event we have tied to updating the health is fired. - That the event is initialized when the component starts. It turns out this is actually a bit difficult to put set up and requires a bit of undocumented work to make your games MonoBehavior's and classes available to your test. We'll walk through how to create this project definition so your tests can reference one another, then we'll look into how to test Mono Behavior's. This is also a bit tricky. It is not possible in Unity to create a MonoBehavior like a standard Unity class by calling something like: ```csharp var myMonoBehavior = new MyCoolNewMonoBehavior(); myMonoBehavior.health = 42; ``` Constructing MonoBehaviors like this simply isn't supported. Instead we'll need to approach this in one of two ways. We can create a GameObject and assign the MonoBehavior to that GameObject or we can leverage one of Unity's testing features the `MonoBehaviorTest`. This class creates a temporary GameObject for your test and attaches your MonoBehavior to it so you can test things. Once we have these systems setup we're able to start exploring the Test Runner more deeply to place our system under test and help validate that it is functioning. The `MonoBehaviorTest` is documented more fully by Unity here: http://bit.ly/2ya97XN Unity's documentation for the Unity Test Runner is currently pretty sparse, but you can find it here: http://bit.ly/2uUVMj2 One thing I try to focus on with tests is creating clear actions/next steps when a test fails. Often it can be tempting to combine tests into larger ones. In some cases this does make sense, however in a lot of cases larger tests can make your test more complex and also mean that when the test fails you no longer know what is wrong. This can lead to a lot of extra debugging that a simpler test can often help you avoid. Join the World of Zero Discord Server: http://bit.ly/2txCKO8
0 notes
Video
youtube
Lets make a component that can track a GameObject's health in Unity and alert other subscribed objects when the health is changed. By allowing objects to subscribe to the health change events as they need to observe them we can remove the need for a majority of objects to constantly track the health of an object over time. Objects simply subscribe when they care, react when they get events and unsubscribe when they don't care about the updates anymore. Theoretically this should be relatively simple and in the long term make interacting with objects in an event based way a lot easier to build on. That's the goal at least. This is largely intended as a proof of concept at this point and so I can learn Unity's event system again. It's been a while since I've used it personally and picking that knowledge back up may take some time. In order to test this event based health tracker we'll add an extra component that allows us to publish health change events and listen for the event that our new component publishes. We can extend this later by adding automated unit tests with the new Unity Test Runner, but for now manually testing ought to serve our purpose. This is part of the Asteroids VR project I'm working on. A VR game based on the classic Asteroids game but with a twist for VR to take advantage of the new experiences we can get when players can move around in their play space. You can see more about the development of Asteroids VR here: https://www.youtube.com/playlist?list=PLEwYhelKHmig7HVi7_WahwXRWPycEJ5xC More documentation on Unity's Events is here: https://ift.tt/2b6nG30 Join the World of Zero Discord Server: https://ift.tt/2txCKO8
0 notes
Video
youtube
Lets make a top down controller that plays a bit more nicely with the mouse. This will allow us to direct our ship by having it move towards the mouse instead of requiring the controller or keyboard input we have required up to this point. While this control scheme doesn't fit every type of game, it can be a strong alternative way to control your characters in other projects. In order to follow the mouse we'll need to get a point in world space that represents where our mouse is. To get this point there are two options we'll consider: 1. Use some algebra to calculate the point in space where our ray will intersect with a specific point on the ground (this only works for directly top down projects). 2. Or raycast onto some sort of invisible surface like a plane. We'll explore the first option here. This is done by using the Camera's `ScreenPointToRay` function to get a ray from our camera that we can use to calculate the actual position of the mouse. ScreenPointToRay will provide us with a ray that has a direction and position. For the most part we care about the direction of the ray. Our function to turn this into a world space position works by using some algebra to derive how many "steps" of the ray it will take to intersect with the ground plane (0 on the y axis). This can be done by dividing the height of the camera by the rays y length. Once we know how many steps of the ray we need to reach the ground we can multiply the rays x and z lengths by that value and add it to the cameras current position to get a result. This resulting value is where our ray passes through the ground plane in world space. It's the point we want our ship to fly towards. To turn that into a direction we are able to compare the player ships position to this new calculated position of the mouse to get a vector that we can plug into the rest of our script. The end result is a ship that flies towards the mouse. It's pretty neat! Source Code: coming soon! Join The World of Zero Discord Channel: https://ift.tt/2txCKO8
0 notes
Video
youtube
There are a number of ways to setup and run a Minecraft server (or any server for that matter). Docker is one of them. Docker is a container platform that is extremely popular throughout the software engineering industry for making server applications easy to build, configure, run and move around inside an environment. It helps define a specification or Image that can contains the entire running environment for your application and creates a set of boundaries around that environment so outside programs won't effect it and so your program won't effect others. This isolation helps create reproducible results. In the case of Minecraft, using Docker enables us to avoid our server and local minecraft instance having conflicting configurations (for example testing out a beta or mod) but also provides a way for our server to be reproducible. This reproducibility is extremely handy because it means we can develop our server on our own PC and then move that server to any other place (the cloud, another PC etc) and get the same results. This makes testing new things really easy, but also makes it really easy to move to host on a local server or in the cloud on any number of providers. In my case the server is tested locally and iterated upon and then moved to a stand-alone server to run the production version of the Minecraft server. In order to preserve the data of our server outside of the container we'll want to create a Docker Volume (https://ift.tt/2EWk6Es). Volumes provide a way to link your operating systems storage and the virtual storage occurring inside of the Docker container. Without this the data is not easily visible outside of docker. The advantage to this is it ensures that accidentally deleting or simply losing our server image does not result in the loss of players data. Docker components are designed to be easily created and destroyed, they are not for storing persistent state by default. Volumes provide a way around this and make preserving your important information possible. The `itzg/minecraft-server` image is available here with more documentation and instructions: https://ift.tt/2HzQYqL Join the World of Zero Discord Server: https://ift.tt/2txCKO8
0 notes
Video
youtube
We have a spaceship that can fly around, but we have a problem. It can fly through things. Lets fix that by changing our current transformation modification into physical forces on a rigidbody! This will allow us to apply force or torque to our ship instead of directly working with the vector positions and rotations. Interestingly, because of the way we've put our ship controller together so far doing this isn't too hard. In the past we've developed three methods of moving our Spaceship controller by modifying the transform. This video will take a look at each one of those and change the logic so that each of them can operate on a rigidbody instead. This will allow our spaceship controller to interact with Unity's Physics system so velocity and angular momentum are used instead of immediate frame-by-frame movement. It also means our ship will actually hit other objects in the world which means it can no longer fly through them. Colliding with a planet for example will cause the ship to stop and potentially apply additional forces to our ship. Source Code: coming soon! The World of Zero Discord Channel: https://ift.tt/2txCKO8
0 notes
Video
youtube
C# is a statically typed language meaning you must specify what type your variables are when declaring them. These types are verified by the compiler as you build your project. However, doing this can in some cases feel redundant, introduce technical debt or just not look nice. A common example might be: ```csharp MyCoolNewClass coolClass = new MyCoolNewClass(); ``` In order to avoid duplicating `MyCoolNewClass` in your code you may use C#'s `var` keyword when doing this in local fields (inside of functions for example). `var` automatically detects the type from the right hand side of your assignment and creates a new variable/field with the given type. This isn't like creating a dynamic type - you don't lose C#'s static typing - instead the type is detected at compile time for you ensuring that you still get intellisense code suggestions, compile errors and warnings and more without having to type a little extra. This doesn't require a constructor on the right hand side to work either. Function output is detected and will function as you'd expect in this case as well. Because the results of this are still statically typed you must have a right hand value when using `var`. ```csharp var myField; ``` Is not valid because the type can't be detected. * Note: This trick only works on local fields. * Read more about how implicit typing in C# works on MSDN: https://ift.tt/2tsGotx Join the World of Zero Discord server: https://ift.tt/2txCKO8
0 notes
Video
youtube
C# includes a method for initializing Lists that means you do not need to repeatedly `Add("foo")` throughout your code. This allows you to specify a set of items immediately after the Lists constructor that causes the items to be sequentially added to the list after its created for you. This works for most collection types including Arrays and Lists. Here's an example of what constructing a list like this might look like. ```csharp // Note: replace angled brackets with correct character! var myList = new List⟨string⟩() { "this", "is", "a", "test" }; ``` Doing this traditionally would look like this: ```csharp // Note: replace angled brackets with correct character! var myList = new List⟨string⟩(); myList.Add("this"); myList.Add("is"); myList.Add("a"); myList.Add("test"); ``` This trick also works with Dictionary's! Here's how: https://youtu.be/lFsgmxzw7IU Join the World of Zero Discord server: http://bit.ly/2txCKO8
0 notes
Video
youtube
C# allows you to seed data into your dictionary when it's constructed by using an initializer function that accepts a series of key, value pairs after its constructor that causes those elements to be automatically inserted into your Dictionary's for you. This is a really handy way to initialize your dictionaries if you already know what you expect to be a part of them or want to use a Dictionary as a lookup table for example. An example of what this might look like: ```csharp // Note: replace angled brackets with correct character! var myList = new Dictionary⟨string,string⟩() { {"key", "value"}, {"key2", "value2"} }; ``` Doing this traditionally would look like this: ```csharp // Note: replace angled brackets with correct character! var myList = new Dictionary⟨string,string⟩(); myList.Add("key", "value"); myList.Add("key2", "value2"); ``` This trick also works for Lists! Here's how: https://youtu.be/F11BhVjmyd0 Join the World of Zero Discord server: http://bit.ly/2txCKO8
0 notes
Video
youtube
C# has the ability to build strings in a number of ways. The simplest is concatenating them, but it's not always the easiest or best solution depending on what you're making. There's a new solution that has been recently introduced to C# that allows you to interpolate strings in a very clean and readable way by embedding variables or functions directly into strings. An example of what using string interpolation like this might look like: ```csharp var name = "World of Zero"; Console.WriteLine($"Hello {name}"); ``` This feature became available in C# 6 and is usable in all versions after that. You may read more about it on MSDN: http://bit.ly/2I0HkiP The World of Zero Discord Server: http://bit.ly/2txCKO8
0 notes
Video
youtube
Unity has made it a bit easier to compute some values in their editor windows by allowing you to enter math formula's into the inspector. This means you may enter formula's when you need to input float's, int's or other number values and Unity will automatically compute the result for you. As an example typing `8^2` will compute 8 squared and set the value to 64. Come Chat with us in the World of Zero Discord server: http://bit.ly/2txCKO8
0 notes