Skip to content

Instantly share code, notes, and snippets.

View MattRix's full-sized avatar

Matt Rix MattRix

View GitHub Profile
@MattRix
MattRix / wrap_subscribe.verse
Last active May 4, 2023 21:01
Send additional data to Subscribe() listeners in Verse
#usage example (when subscribing to an event that returns an agent)
ButtonDevice.InteractedWithEvent.SubscribeAgent(OnButtonInteract, "Hello!")
OnButtonInteract(Agent : agent, Text : string) : void =
Print("Button interacted with {Text}!")
#usage example (when subscribing to an event that returns tuple(), aka an empty tuple)
CampfireDevice.CampfirePulseEvent.SubscribeEmpty(OnCampfirePulse, 90210)
OnCampfirePulse(Number : int) : void =
@MattRix
MattRix / SingleImagePostMaterial.txt
Created May 2, 2023 22:17
Post processing material for UE5/UEFN material graph to show an image on screen (copy and paste into the graph editor)
Begin Object Class=/Script/UnrealEd.MaterialGraphNode_Root Name="MaterialGraphNode_Root_16"
Material=/Script/UnrealEd.PreviewMaterial'"/Engine/Transient.PreviewMaterial_2"'
NodePosX=144
NodePosY=-80
NodeGuid=DA645A0D405D999F05550EB2B20E74E3
CustomProperties Pin (PinId=94B10B244638D93ADC813DA0DB8A360A,PinName="Base Color",PinType.PinCategory="materialinput",PinType.PinSubCategory="5",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
CustomProperties Pin (PinId=2BA1B6FE4FAF4CE973853CAD1EB7925E,PinName="Metallic",PinType.PinCategory="materialinput",PinType.PinSubCategory="6",PinType.P
@MattRix
MattRix / singleton.verse
Created April 24, 2023 15:27
Singleton in Verse
global := class<varies><concrete>():
var MaybeMainDevice : ?main_device = false
GetMainDevice():main_device =
if(MainDevice := Global.MaybeMainDevice?) then MainDevice else main_device{}
Global : global = global{}
#in the device's OnBegin you call
set Global.MaybeMainDevice = option{Self}
@MattRix
MattRix / routine.verse
Last active April 22, 2023 14:36
Cancelable Spawned Coroutines in Verse (advanced version)
<#> Usage
MyRoutine := SpawnRoutine(SomeLongRunningTask)
MyRoutine.Cancel()
SpawnRoutine<public>(Func : type{_()<suspends>:void}):routine =
Routine := routine{Func := Func}
Routine.Start()
return Routine
routine<public> := class():
@MattRix
MattRix / routine.verse
Created April 21, 2023 16:19
Cancelable Coroutines with Verse (using race)
<#> Usage
Routine := SpawnRoutine(SomeLongTask)
Routine.Cancel()
SpawnRoutine(Func : type{_()<suspends>:void}):routine =
Routine := routine{Func := Func}
Routine.Start()
return Routine
routine := class():
@MattRix
MattRix / sort.verse
Created April 21, 2023 15:43
Parmetric Quicksort for Arrays in Verse
<#> Usage:
SortedItems := Sort(Items, true, CompareInt)
Sort(Items : []t, IsAscending : logic, Comparer: type{_(:t, :t)<computes> : int} where t : type)<computes> : []t =
if (Items.Length > 1, Pivot := Items[Floor(Items.Length/2)]):
Left := for(Item : Items, Comparer(Item, Pivot) = -1) do Item
Middle := for(Item : Items, Comparer(Item, Pivot) = 0) do Item
Right := for(Item : Items, Comparer(Item, Pivot) = 1) do Item
@MattRix
MattRix / slow_down_device.verse
Last active March 31, 2023 18:09
A device that shows some kind of memory leak in UEFN/Verse (creating and removing a bunch of UI widgets every frame)
using { /Verse.org/Simulation }
using { /Verse.org/Verse }
using { /Verse.org/Colors }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/UI }
using { /Fortnite.com/Devices }
using { /Fortnite.com/UI }
@MattRix
MattRix / movechecker_device.verse
Created March 29, 2023 19:11
A Verse script that detects when the player starts and stops moving
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
movechecker_device := class(creative_device):
@MattRix
MattRix / FormatRoundedFloatAsString.verse
Last active April 25, 2023 14:54
A function to write a float to a string with a certain numer of decimal places in Verse
FormatRoundedFloatAsString(Input : float, NumDigitsAfterDecimal : int) : string =
if:
Multiplier := Pow(10.0, NumDigitsAfterDecimal * 1.0)
RoundedValue := float[Round[Input * Multiplier] * 1.0] / Multiplier
BeforeDecimal := Floor[RoundedValue]
AfterDecimal := Abs(Round[(RoundedValue - BeforeDecimal * 1.0)*Multiplier])
var AfterDecimalString : string = ToString(AfterDecimal)
#pad the number after the decimal with leading zeroes
for (It := 0..(NumDigitsAfterDecimal - AfterDecimalString.Length - 1)):
@MattRix
MattRix / movement_detector_device.verse
Last active March 28, 2023 22:48
Movement Detector Device in Verse for UEFN
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
movement_detector_device := class(creative_device):
@editable
MinimumMovementDistance : float = 100.0