Skip to content

Instantly share code, notes, and snippets.

@kraj0t
kraj0t / Unity External Assets Folder.md
Last active April 8, 2026 09:34
External assets folder for Unity in Windows

This is how to setup an assets folder that lives outside of your Unity project's Assets folder. This external folder can be shared across multiple Unity projects, which is great for keeping all your editor tools in one place, without the need to copy-paste the changes all the time.

  1. Create folder for your external assets. For this guide, I will use the folder path "C:\MyExternalUnityAssets"
  2. Open a shell window running cmd.exe and type mklink /J "C:\git\MyUnityProject\Assets\__MyExternalAssets" "C:\MyExternalUnityAssets", replacing the path to your Unity project.
  3. To hide your folder from git, edit the file .git/info/exclude in your local git repo and add these in new lines at the end: Assets/__MyExternalAssets/ Assets/__MyExternalAssets.meta
  4. (Optional but highly recommended) Sync your external folder with some version control. Google Drive is probably good enough.

Note: Unity shows a warning about symlinks every time the editor opens, but so far I have not had any issue.

@kraj0t
kraj0t / Shader notes tips and tricks.md
Last active July 25, 2025 20:02
Shader notes, tips and tricks

Misc

  • Use [ToggleUI] attribute for checkboxes. Never use [Toggle] as it implicitly creates a keyword.
  • Apply default textures to shaders in their inspector.
  • Related to the previous point, the [NonModifiableTextureData] attribute forbids the user from assigning a different texture.
  • Remember that there are special HLSL semantics that are rarely used, such as SV_Depth or SV_Face
  • Add #pragma editor_sync_compilation to avoid the cyan color blink when shader gets recompiled

@kraj0t
kraj0t / DebugShaderGlobalsProfile.cs
Last active March 21, 2025 21:07
Asset that I like to use for quick debugging of shader values
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
/// <summary>
/// Convenience asset for testing different global shader values in the editor.
/// </summary>
[CreateAssetMenu(fileName = "DebugShaderGlobalsProfile", menuName = "__AURELIO/DebugShaderGlobalsProfile")]
public class DebugShaderGlobalsProfile : ScriptableObject
@kraj0t
kraj0t / InternalClassReflectionExtendedEditor.cs
Last active April 24, 2024 10:50
Extend or modify built-in private Editor classes that are not exposed in the API, such as MeshRendererInspector or TransformInspector
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;
/// <summary><para>Use this class to override a built-in Editor that is not publicly exposed in the API.</para>
///
@kraj0t
kraj0t / ClampedCurveAttribute.cs
Last active March 13, 2024 10:21
Clamped AnimationCurve GUI - constrains the curve to a range, typically 0-1
using System;
using UnityEngine;
/// <summary>Constrains an AnimationCurve to a specific range. Use the default constructor for the typical 0-1 range. Use Mathf.Infinity to unconstrain specific values.</summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class ClampedCurveAttribute : PropertyAttribute
{
public Rect ranges;
public ClampedCurveAttribute()
@kraj0t
kraj0t / UsingCsCodeInHLSL.cs
Last active January 5, 2025 14:34
How to include C# code in an HLSL file - useful for sharing code between CPU and shader without duplicating any files
// Share code between HLSL (shaders) and C#
//
// Limitations:
// - Cannot use #include
// - Must use defines to hide certain keywords, such as public, private, protected, or any other object-oriented programming keywords
// - Use defines to convert half or fixed to your desired C# equivalent
// - Must always write f after float literals
// - Use #if !MY_DEFINE instead of #ifndef MY_DEFINE
// - #define cannot be used with a value in C#, not even inside an '#if SHADER_TARGET' block. Therefore, you have two options for declaring valued constants:
// a. Declare each constant separately in HLSL (using 'static const float MyConstant = 1.0f') and in C# (using 'const float MyConstant = 1.0f'). C# does not support 'static const'.
@kraj0t
kraj0t / CloseEditorWindowShortcut.cs
Last active March 3, 2024 17:21
[Unity] Editor shortcut for closing the window/tab that is currently focused (I just cannot live without it heheh)
using UnityEditor;
using UnityEditor.ShortcutManagement;
using UnityEngine;
public class CloseEditorWindowShortcut
{
[Shortcut("Window/Close", KeyCode.W, ShortcutModifiers.Control)]
private static void CloseTab(ShortcutArguments args)
{
if (EditorWindow.focusedWindow != null)
@kraj0t
kraj0t / MeshDataCache.cs
Created May 9, 2022 21:26
[Unity] MeshDataCache - collect mesh data and modify it before applying the changes to the Mesh. Compatible with VertexHelper
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
namespace kraj0t.Rendering
{
/// <summary>
/// This class is a convenient way of collecting mesh data and avoiding having to constantly query and dirty a Unity mesh, which is BAD for performance.
///
@kraj0t
kraj0t / ffmpeg_batchAudiosToVideos.bat
Created May 1, 2022 18:46
ffmpeg - Windows batch file - convert m4a audios to videos
@echo off
if not exist *.m4a (
echo This directory contains no m4a files.
) else (
for %%f in (*.m4a) do (
:: Option 1. LOOPING VIDEO
ffmpeg -i "%%f" -stream_loop -1 -i "loop-360p.mp4" -shortest "%%~nf.mp4"
:: Option 2. STATIC BLACK IMAGE
@kraj0t
kraj0t / .Raycast inside RenderTexture.gif
Last active March 3, 2024 10:50
[Unity] PhysicsRaycaster for indirectly casting rays inside a quad that has a RenderTexture on it
.Raycast inside RenderTexture.gif