Experimental UdonSharp compiler extension for static fields backed by one scene-wide global store.
Udon does not expose native C# static memory. This package emulates static field storage by creating exactly one __UdonStaticGlobalStore object in the scene and lowering static field access to typed Data arrays on that store.
Install through VCC/VPM.
Required VPM dependency:
com.vrchat.worlds >= 3.9.0Repository release tags should match package.json version, for example 0.1.0 or v0.1.0.
Source:
using UdonSharp;
using UnityEngine;
public class Example : UdonSharpBehaviour
{
private static int Counter = 10;
private static float Elapsed;
public int visibleCounter;
public float visibleElapsed;
private void Update()
{
Counter++;
Elapsed += Time.deltaTime;
visibleCounter = Counter;
visibleElapsed = Elapsed;
}
}
Lowered shape:
private K13A.UdonStatic.Runtime.UdonStaticGlobalStore __udonStaticStore;
private K13A.UdonStatic.Runtime.UdonStaticGlobalStore __UdonStatic_GetStore()
{
if (__udonStaticStore == null)
__udonStaticStore = UnityEngine.GameObject.Find("__UdonStaticGlobalStore")
.GetComponent<K13A.UdonStatic.Runtime.UdonStaticGlobalStore>();
return __udonStaticStore;
}
Counter becomes __UdonStatic_GetStore().IntData[index], Elapsed becomes __UdonStatic_GetStore().FloatData[index], and every instance resolves the same singleton store object.
Supported MVP:
UdonSharpBehaviour classes.Counter++.Example.Counter = 10, including from another UdonSharp behaviour compiled in the same pass.__UdonStaticGlobalStore.Data storage:
IntData, FloatData, BoolData, StringDataLongData, DoubleDataVector2Data, Vector3Data, QuaternionData, ColorDataGameObjectData, TransformDataObjectData UnityEngine.Object fallbackLimitations:
Examples:
Examples/UdonStaticCounterExample.cs: static fields shared through the global store and updated every frame.Editor tests:
Editor/Tests/UdonStaticLowererTests.cs: validates global store lowering, same-class access, cross-class access, local shadowing, and ignored non-UdonSharp classes.com.kibalab.udonstatic
Undefined
0.1.2
2022.3 or later
No dependencies
No legacy packages
Undefined