Uploaded June 2021 | Updated November 2026, 3 hours ago
LINQ for Unity is a new tool I'm building that allows you to run C# queries, typically LINQ, that you can then use to modify objects in your scenes easily. This allows you to select all of the Colors of your scenes Lights for example and easily edit them all or quickly change the positions of objects that meet a certain criteria.
One of the challenges the tool is currently facing is handling value types. These are common in Unity and occur when any primitive types (like `float`, `int`) or any structs (like `Vector3`, `Color`) are used. Instead of reference types which point to the location of data a value type will copy data when it is assigned. This means that if we try to select all of an objects positions that we will only retrieve the **values** of those positions. These values are read-only and if we do change them they will not effect the Transform they are a member of.
In this stream we will be designing, prototyping and building a solution to this value type problem using reflection and exploring other alternatives.
This is from a Live Stream I did on Twitch! You can follow me there to get notified the next time I go live: twitch.tv/worldofzerodev
Join the World of Zero Discord Server: discord.gg/hU5Kq2u
LINQ for Unity is a new tool I'm building that allows you to run C# queries, typically LINQ, that you can then use to modify objects in your scenes easily. This allows you to select all of the Colors of your scenes Lights for example and easily edit them all or quickly change the positions of objects that meet a certain criteria.
One of the challenges the tool is currently facing is handling value types. These are common in Unity and occur when any primitive types (like `float`, `int`) or any structs (like `Vector3`, `Color`) are used. Instead of reference types which point to the location of data a value type will copy data when it is assigned. This means that if we try to select all of an objects positions that we will only retrieve the **values** of those positions. These values are read-only and if we do change them they will not effect the Transform they are a member of.
In this stream we will be designing, prototyping and building a solution to this value type problem using reflection and exploring other alternatives.
This is from a Live Stream I did on Twitch! You can follow me there to get notified the next time I go live: twitch.tv/worldofzerodev
Join the World of Zero Discord Server: discord.gg/hU5Kq2u

: Multiline strings expand the normal textbox a fixed number of vertical lines. This is less flexible than a `TextArea` but can still be useful in some situations.
* [`TextArea`](https://docs.unity3d.com/ScriptReference/TextAreaAttribute.html): Text Areas span between a minimum and maximum number of lines and - unlike a `Multiline` attribute - they will add scrollbars if the text exceeds the maximum number of lines. Additionally the `TextArea` spans the entire width of the Inspector giving more room to type.
The JSON.NET documentation is available here: https://www.newtonsoft.com/json/help/html/Introduction.htm
***
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u An Intro to Json Serialization and Deserialization in Unity](https://i.ytimg.com/vi/3F4HjM_5hZY/mqdefault.jpg)

![Live Coding Handles and Custom Editors in Unity
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... Ive never really used them. Its 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 Unitys Handle features? How about creating a custom editor with a context menu we can consume? Well 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 Unitys website: https://docs.unity3d.com/ScriptReference/Handles.html
The documentation for `GenericMenu` is also on Unitys site. More info here: https://docs.unity3d.com/ScriptReference/GenericMenu.html
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Live Coding Handles and Custom Editors in Unity](https://i.ytimg.com/vi/3efiobxsurY/mqdefault.jpg)

![Using C#s nameof Expression - C# Quick Tip
The `nameof` expression allows you to convert a variable, property, type or function into a string that represents its name. This can be an alternative to typing out strings directly in your code when you need to reference the name of an object in your code. This is really common when implementing `INotifyPropertyChanged` events and has a number of other uses as well.
The advantage of using `nameof` compared to writing out the object in a string is that the dotnet compile will fail if the reference in your nameof expression does not exist. This can help catch issues during refactoring when elements are renamed. Typically, when using strings directly those references can become runtime errors and potentially be very difficult to identify (ex. a UI element not updating because it no longer receives its Property Update notification). `nameof` can help avoid that issue in your code.
Some examples of how to use `nameof`:
```csharp
class Program
{
public float aVariableNamedFoo = 3.14f;
public float Foo =˃ aVariableNamedFoo;
static void Main(string[] args)
{
Console.WriteLine($Class: {nameof(Program)}); //Class: Program
Console.WriteLine($Variable: {nameof(aVariableNamedFoo)}); //Variable: aVariableNamedFoo
Console.WriteLine($Property: {nameof(Foo)}); //Property: Foo
Console.WriteLine($Function: {nameof(Main)}); //Function: Main
}
}
```
`nameof` can also be used against members of other objects. For example the `nameof` a Lists Count can be retrieved using:
```csharp
var contents = new List˂Page˃();
Console.WriteLine($List Count: {nameof(contents.Count)}); //List Count: Count
```
You can learn more about using `nameof` in the C# documentation here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof
***
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Using C#s nameof Expression - C# Quick Tip](https://i.ytimg.com/vi/48iBTUYjf8k/mqdefault.jpg)

. These are very Unity specific and include a lot of custom code to integrate cleanly into Unitys lighting systems. Because of this, a `Surface Shader` doesnt require you to create any custom lighting and will automatically function and look natural inside of most environments. It will receive lights, cast shadows and more.
That isnt the case for the `Unlit Shader` which removes the Unity specific `surface` function for more traditional `vertex` and `fragment` ones which align very closely with how a shader might work in OpenGL or other engines (though not necessarily identically!). Like the name suggests an `Unlit Shader` has no lighting effects, the default shader will just draw a texture onto a mesh and be as true to color as possible for that texture.
Just because the shader doesnt include things like lighting doesnt mean we cant add our own though. First though, we should take a look at vertex and fragment shader functions.
- `#pragma vertex vert`: will declare a function for a vertex shader named `vert`. Vertex shaders jobs are to transform a mesh into a camera based position so that it can be drawn onto the screen. This is done using a series of matrix multiplications. Luckily that work is already done inside of Unitys templates with the code `o.vertex = UnityObjectToClipPos(v.vertex)`. That code accepts an input vertex which will be a point relative to the original position of the object (in our example we use 3 boxes, the *input* of the 3 boxes is the same vertices but the *output* is modified because while the cubes are identical theyre in different positions). Vertex shaders can store other information than the position of a vertex such as the color or normal direction of the mesh and we can introduce extra information we may need here as well.
- `#pragma fragment frag` will declare a fragment shader with the name `frag`. These are passed the output information from the vertex shader and are responsible for actually putting color on the screen. Theyre called `fragments` and not `pixels` here because its actually possible for multiple `fragments` to be drawn in a single pixel for a variety of reasons (meshes overlapping one another for example). Inside the `fragment shader` the values from the vertex shader are not necessarily received unmodified. Your graphics cards will do some fancy interpolation for you between these two steps. If you think of the vertices in our mesh like numbers on a number line you might end up with a line that has 0 and 1 on it. The fragment shader represents the entire line including 0 and 1, but also all the numbers in-between. In the cases of those intermediate numbers we dont usually want duplicates of 0 and 1 but the unique value at that position in the number line. Fragment shaders will do this calculation for us and interpolate colors, vectors and more for us and pass those interpolated values into the input of the fragment shader.
Using this information we can introduce a custom lighting effect by passing the normal value of each vertex into our shader. This will give us a direction facing away from the face of the mesh (the normal of the floor - as an example - is straight up). Using a `dot product` we can compare the result of that normal value to a global light source to determine how strongly the light is impacting that point on the mesh. A very quick sample of what the code to do this might look like is this:
```shader
fixed3 lightDirection = fixed3(0, -1, 0); // Create a light source from directly overhead
// A max function is used here to prevent negative values during our math.
fixed lightIntensity = max(-1 * dot(lightDirection, input.worldNormal), 0);
```
Code for the full shader will be released in the next few days.
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Writing Our Own Diffuse Lighting Shader](https://i.ytimg.com/vi/4XfXOEDzBx4/mqdefault.jpg)


