Skip to main content

CE Core

CE.Core provides low-level building blocks used across CE runtime and compile-time features, including the CECallback type and compiler-facing attributes.

Quick Start

using UdonSharp;
using UdonSharp.CE.Core;
using UnityEngine;

public class CallbackExample : UdonSharpBehaviour
{
private CECallback _onDone;

void Start()
{
_onDone = CECallback.Create(this, nameof(OnDone));
_onDone.Invoke();
}

public void OnDone()
{
Debug.Log("Done");
}
}

CECallback API Reference

MemberDescription
TargetTarget behaviour that owns the method to invoke.
MethodNameMethod name to invoke on the target.
IsValidTrue when Target and MethodName are set.
Invoke()Invokes the callback if valid.
InvokeWithLogging(string context)Invokes with debug logging when invalid.
Create(UdonSharpBehaviour, string)Convenience factory for CECallback.
NoneInvalid callback value.

Optimization And Compiler Attributes

These attributes are declared for CE compiler features. Only CEPreserveAction is currently enforced by the compiler pipeline.

AttributePurposeStatus
CENoOptimizeOpt out of CE optimizations on a member or type.Reserved
CENoInlinePrevent inlining of a method.Reserved
CEInlineRequest inlining of a method.Reserved
CENoUnrollPrevent loop unrolling in a method.Reserved
CEUnrollRequest loop unrolling.Reserved
CEConstMark a field as a compile-time constant.Reserved
CEDebugOnlyRemove a method in release builds.Reserved
CEPreserveActionPrevent Action-to-CECallback transformation.Active

Notes On Action Transformation

CE converts parameterless Action usage to CECallback at compile time. This means:

  • Action<T> and other delegate types are not supported.
  • Simple lambdas like () => Method() are converted, but closures are not.
  • Use callback.Invoke() (not callback?.Invoke()) after transformation.

Lambda Inlining (Supported Subset)

CE can inline a small subset of lambdas to avoid delegate usage:

  • Immediate invocation: (() => { ... })(); is inlined as a direct block.
  • CE collection helpers: List, Queue, Stack, and CEList support ForEach, ForEachWithIndex, and ForEachUntil with lambdas.

Notes:

  • ForEachUntil requires an expression body or a single return statement.
  • For unsupported lambda shapes, rewrite as explicit loops or extract a method and use CECallback.

Common Pitfalls

Bad

using System;

public class Example : UdonSharpBehaviour
{
private Action _onDone;

void Start()
{
_onDone = () => OnDone();
_onDone?.Invoke(); // `?.` is not valid after Action becomes CECallback
}
}

Good

using System;

public class Example : UdonSharpBehaviour
{
private Action _onDone;

void Start()
{
_onDone = () => OnDone();
_onDone.Invoke();
}
}