Skip to content

Unsafe usage (Advanced)

Adjust also offers the option to use direct pointers instead of the AdjustableValue class. Note that this is not recommended, and special care needs to be taken when using it. Pointers that are passed in must be pinned.

INFO

To enable unsage usage, you must add the DEBBY_ADJUST_UNSAFE_POINTERS symbol to the Scripting Define Symbols field in the Player Settings.

csharp
// CRITICAL: Pin the object to prevent GC from moving it
var objHandle = GCHandle.Alloc(dataContainer, GCHandleType.Pinned);

dataContainer.boolValue = true;
dataContainer.intValue = 42;

bool* boolPtr;
int* intPtr;

fixed (bool* bp = &dataContainer.boolValue)
fixed (int* ip = &dataContainer.intValue)
{
    boolPtr = bp;
    intPtr = ip;
}

Debby.Adjust.NewContext("Unsafe Context")
   .AddValueUnsafe("Bool Value", boolPtr)
   .AddValueUnsafe("Int Value", intPtr)
   .Build();

// ----------//

private struct DataContainer
{
    public int  intValue;
    public bool boolValue;
}