Uploaded February 2020 | Updated November 2026, 1 hour ago
I've been experimenting with embedding Roslyn (the .NET compiler) into Unity. Here is what I've built so far.
Roslyn is a compiler for .NET that includes a package for scripting and expressions. This allows you to write C# code into standard strings and then compile and execute the code in memory. We can extend this further by integrating it with Unity and exposing the default types from our game. The end result of all of this is the ability to write basic strings with C# code in them that we can evaluate later to interact with any part of our system we choose. There are a number of potential use cases for this from debugging your compiled game with an embedded terminal to creating a game that teaches C#.
This solution does open up some potential for running code that should not be run. If you're trying this, please use caution when considering allowing code from the internet or other users to be run. This can have severe consequences if abused. Someone once said great power demanded great responsibility and that's the case here.
## Some Examples
Calculate 2³ power using `System.Math`:
```csharp
result = CSharpScript.EvaluateAsync[double]("System.Math.Pow(2,3)").GetAwaiter().GetResult();
```
Find a `Camera` object in the current scene:
```csharp
cameraObject = await CSharpScript.EvaluateAsync[GameObject]("GameObject.FindObjectsOfType[Camera]().First().gameObject",
ScriptOptions.Default.WithImports( // Import namespaces to simplify scripts
"System",
"System.Collections.Generic",
"System.Linq",
"UnityEngine"
).AddReferences( // Include additional assemblies
typeof(System.Linq.Enumerable).Assembly,
typeof(UnityEngine.Transform).Assembly
));
```
The Roslyn Scripting API is documented on GitHub: github.com/dotnet/roslyn/wiki/Scripting-API-Samples
You can find the Nuget package here: nuget.org/packages/Microsoft.CodeAnalysis.CSharp.Scripting
Join the World of Zero Discord Server: discord.gg/hU5Kq2u
I've been experimenting with embedding Roslyn (the .NET compiler) into Unity. Here is what I've built so far.
Roslyn is a compiler for .NET that includes a package for scripting and expressions. This allows you to write C# code into standard strings and then compile and execute the code in memory. We can extend this further by integrating it with Unity and exposing the default types from our game. The end result of all of this is the ability to write basic strings with C# code in them that we can evaluate later to interact with any part of our system we choose. There are a number of potential use cases for this from debugging your compiled game with an embedded terminal to creating a game that teaches C#.
This solution does open up some potential for running code that should not be run. If you're trying this, please use caution when considering allowing code from the internet or other users to be run. This can have severe consequences if abused. Someone once said great power demanded great responsibility and that's the case here.
## Some Examples
Calculate 2³ power using `System.Math`:
```csharp
result = CSharpScript.EvaluateAsync[double]("System.Math.Pow(2,3)").GetAwaiter().GetResult();
```
Find a `Camera` object in the current scene:
```csharp
cameraObject = await CSharpScript.EvaluateAsync[GameObject]("GameObject.FindObjectsOfType[Camera]().First().gameObject",
ScriptOptions.Default.WithImports( // Import namespaces to simplify scripts
"System",
"System.Collections.Generic",
"System.Linq",
"UnityEngine"
).AddReferences( // Include additional assemblies
typeof(System.Linq.Enumerable).Assembly,
typeof(UnityEngine.Transform).Assembly
));
```
The Roslyn Scripting API is documented on GitHub: github.com/dotnet/roslyn/wiki/Scripting-API-Samples
You can find the Nuget package here: nuget.org/packages/Microsoft.CodeAnalysis.CSharp.Scripting
Join the World of Zero Discord Server: discord.gg/hU5Kq2u

 and [Nuget](https://www.nuget.org/packages/TrieNet/). You can find more documentation and learn about its other features here: https://github.com/gmamaladze/trienet
If you want to learn more about how Tries work as a data structure you can learn more about that on Wikipedia: https://en.wikipedia.org/wiki/Trie
If youre interested in how to build a `Trie` from scratch weve done that in an earlier video you can find here: https://www.youtube.com/watch?v=4nmVXKu6e_Q
For more information about the Mermaid diagrams I use at the start of this video, check out [my video on Mermaid JS](https://www.youtube.com/watch?v=7_2IroEs6Is). Recently support for these diagrams was even [added to GitHub](https://docs.github.com/get-started/writing-on-github/working-with-advanced-formatting/creating-diagrams).
***
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Trie, Trie Again - A String Search Data Structure](https://i.ytimg.com/vi/ZgZXW_V-2lo/mqdefault.jpg)



![Using PowerShell to Create a Symbolic Link on Windows
Symbolic Links allow you to create a reference in your file system to another file or directory. This allows you to reference the same file in multiple places without having to physically copy it into each place. This can save storage space and also allows a single change to the file to be seen by every location that links to it as well.
In this video well be taking a look at how to create these Symbolic Links from PowerShell using a version of the `New-Item` commandlet. In order to take advantage of this youll need to be running in an Administrator PowerShell or you may see the New-Item : Administrator privilege required for this operation error. This solution is able to create symbolic links between files or directories and also will detect if the target item you are creating the link to exists or not before generating the link.
In order to create the symlink in PowerShell youll run this command:
```ps1
New-Item -ItemType SymbolicLink -Path [path] -Target [target]
```
This will create a new Item at the provided path that represents a link to the target file or directory.
If you prefer Command Prompt you can learn how to make a symbolic link in Command Prompt here: https://youtu.be/w2gxWTOPw7U
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Using PowerShell to Create a Symbolic Link on Windows](https://i.ytimg.com/vi/_VnONfOgP8M/mqdefault.jpg)


.
When used in a function or property which returns an `IEnumerable`, yield will provide two features. You may `return` the next value in the set or `break` out of the loop - effectively terminating the set. Values `return`ed from a `yield` keyword are composed into the enumerable set as your code evaluates. Yield statements are evaluated lazily (meaning the function generating the enumerable object is not generated completely before the first element is returned), this means that after returning with `yield` the code in the function will continue from the point it returned from including preserving the state (such as local variable values).
Using these concepts we can create a function which returns all positive integers between 1 and a max value.
```csharp
// Note: youll need to replace the IEnumerable˂int˃ with correct syntax as well as the ˃= symbol
public static IEnumerable˂int˃ PositiveInts(int max) {
int i = 1;
while(true) {
yield return i++;
if (i ˃= max) {
yield break;
}
}
}
```
* `yield return`: returns the next value in an `IEnumerable`.
* `yield break`: marks the end of the `IEnumerable`.
More information about using `yield` with some other examples is available here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/yield
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Using C#s Yield Keyword](https://i.ytimg.com/vi/bsZjfuTrPSA/mqdefault.jpg)

