Skip to content

Instantly share code, notes, and snippets.

View JonahGrimm's full-sized avatar
😁

Jonah Grimm JonahGrimm

😁
View GitHub Profile
@JonahGrimm
JonahGrimm / LogNetMode.cpp
Created October 22, 2023 03:18
Creates a console command that logs the UnrealEngine net mode for the given game instance
#include "GameInstanceCommands.h"
void UGameInstanceCommands::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
TestCmd = IConsoleManager::Get().RegisterConsoleCommand( TEXT("LogNetMode"),
TEXT("Outputs the net mode to the console."),
FConsoleCommandDelegate::CreateUObject( this, &UGameInstanceCommands::LogNetMode ),
ECVF_Default );
}
@JonahGrimm
JonahGrimm / RunWithLog.bat
Created October 22, 2023 03:09
Run UnrealEngine packaged development executable with log window
:: Ensure the project is packaged using the "Development" configuration
@echo off
:: Change dir to the same directory as this batch file
cd /d "%~dp0"
:: Iterate through all executables in this directory
for %%i in (*.exe) do (
:: Run the executable
@JonahGrimm
JonahGrimm / $PolymorphicSerializationExample.cs
Last active June 14, 2023 20:35
The following is a basic example of Polymorphic Serialization in Unity. It uses Food as the concept for a base class and the derived types are different types of foods. It is complete with a property drawer so that it is easy to work with. Be sure to remove the $ from the first file's name. That's just for sorting.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PolymorphicSerializationExample : MonoBehaviour
{
[SerializeReference] public List<Food> classes = new List<Food>();
#if UNITY_EDITOR
private void OnValidate()
using Cinemachine;
using UnityEngine;
public static class MethodExtensions
{
public static Vector3 WorldToViewportPoint(this CinemachineVirtualCameraBase vcam, Vector3 position)
{
// CyRaid https://forum.unity.com/threads/reproducing-cameras-worldtocameramatrix.365645/
Matrix4x4 worldToCameraMatrix = Matrix4x4.Inverse(Matrix4x4.TRS(vcam.State.FinalPosition, vcam.State.FinalOrientation, new Vector3(1, 1, -1)));
Matrix4x4 projectionMatrix = Matrix4x4.Perspective(vcam.State.Lens.FieldOfView, vcam.State.Lens.Aspect, vcam.State.Lens.NearClipPlane, vcam.State.Lens.FarClipPlane);
@JonahGrimm
JonahGrimm / TMPro-Billboard.shader
Created October 4, 2022 10:29 — forked from Spongert/TMPro-Billboard.shader
Unity TextMeshPro Billboard / always facing camera shader
Shader "TextMeshPro/Distance Field-BillboardFacing"
{
// Very, very slightly tweaked version. Works in 2022.1.18f1 URP 13.1.8
// Enjoy!
// - Jonah
// Billboarding version for TextMeshPro (tested in 2018.3), based on default Distance Field shader.
// ** Important part is to DISABLE the dynamic batching! (happens in this shader) **
// ...Took a while to figure out that one.