Skip to Content

Best Practices For Writing Flayer Functions

When writing Flayer functions for the Nunu SDK, it’s important to follow best practices to ensure your SDK integrates smoothly with the AI agent. This guide provides recommendations for structuring, organizing, and writing Flayer functions in Unity.

Organization

  • Create a dedicated folder for your Flayer functions (e.g., Assets/Scripts/FlayerFunctions/)
  • Group related Flayer functions into logical static classes (e.g., InventoryFunctions.cs, NavigationFunctions.cs)
  • Keep SDK-specific code separate from your core game logic for better maintainability

Integration

  • Always wrap SDK-related code in #if USE_NUNU_SDK directives:
#if USE_NUNU_SDK using Nunu.Flayer; // Your SDK-specific code here #endif
  • No scene setup is required. The SDK bootstraps itself before the first scene loads and registers your Flayer functions automatically for every new connection.

Design

Use coroutines for long tasks that span over multiple frames. Otherwise you block the main thread!

Never Block the Main Thread

  • Use coroutines for long operations
  • Break up complex operations into multiple frames
  • Avoid synchronous file I/O or network calls

Avoid Memory Leaks

  • Clean up subscribed events
  • Dispose of Unity objects properly
  • Don’t hold unnecessary references

Don’t Bypass Error Handling

  • Log meaningful messages with UnityEngine.Debug — Unity logs are forwarded to the recording automatically while connected
  • A handler exception is returned to the caller as an EL5 error, so let unexpected failures surface rather than swallowing them
Last updated on