I would like to request a single, pre-defined static DataDictionary public field that can be freely used in Udon.
(This is not a request to allow users to define arbitrary static fields in U#.)
## Background
Currently, Udon (U#) does not allow defining static fields.
As a result, sharing state or references across multiple components often requires alternative approaches.
At least in my case, when trying to implement a singleton-like pattern, I tend to rely on search-based approaches such as
GameObject.Find
.
This can lead to increased computational cost due to repeated search operations.
## Proposal
I propose adding one shared static DataDictionary public field, provided by Udon itself.
The idea is:
  • Users do not define static fields themselves
  • Instead, a single shared DataDictionary is provided by the system
  • All Udon/U# scripts can access it
By limiting this to a single DataDictionary, it keeps the scope controlled while still enabling many practical use cases.
## Benefits
Having a shared DataDictionary would make it easier to:
  • Avoid repeated
    GameObject.Find
    calls
  • Share references across systems in a more flexible way
## Expected Behavior
The shared DataDictionary is expected to behave as instance-scoped temporary storage:
  • Initialized when joining a world
  • Cleared when leaving the world
## Example Usage
Example of registering a reference:
using UdonSharp;
using UnityEngine;
using VRC.SDK3.Data;
public class GlobalRegistry : UdonSharpBehaviour
{
private const string Key = "__global_registry_player_manager__";
private const string ObjectName = "__UdonGlobalRegistry_PlayerManager__";
public static GlobalRegistry Instance
{
get
{
if (!UdonSharedData.TryGetValue(Key, out DataToken token))
{
GameObject obj = GameObject.Find(ObjectName);
if (obj == null)
return null;
GlobalRegistry instance = obj.GetComponent<GlobalRegistry>();
if (instance == null)
return null;
UdonSharedData[Key] = instance;
}
return (GlobalRegistry)token.Reference;
}
}
}
Example of retrieving it:
using UdonSharp;
using UnityEngine;
public class SomeSystem : UdonSharpBehaviour
{
public override void Interact()
{
GlobalRegistry instance = GlobalRegistry.Instance;
if (instance != null)
{
Debug.Log(instance.name);
}
}
}