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_SDKdirectives:
#if USE_NUNU_SDK
using Nunu.Flayer;
// Your SDK-specific code here
#endif- Place the NunuManager prefab in the scene where agent should start playing the game. Usually after main loading screen.
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 error messages
- Provide proper feedback to the AI agent
Last updated on