Getting Started
Your First Script
Let's create a behavior that rotates an entity every frame.
Step 1: Create the File
Create SafiEngine/Core/src/behaviors/SpinBehavior.cpp:
Step 2: Register the Behavior
In SafiEngine/Core/src/Behavior.cpp, add the forward declaration and call:
Step 3: Add to CMake
In SafiEngine/Core/CMakeLists.txt, add the source file:
Step 4: Rebuild
Step 5: Attach in the Editor
- Select an entity in the Scene Hierarchy
- Click Add Component > NativeScript
- Select Spin from the Behavior dropdown
- Press Play and watch the entity rotate
Using the "New Behavior" Button
The Inspector's NativeScript component has a New Behavior button that generates a template .cpp file in your project's assets/scripts/ directory. This gives you the boilerplate, but you still need to add the file to CMake and rebuild.
Anatomy of a Behavior
Tip
Each entity gets its own behavior instance. Private member variables are per-entity state that persists across frames during a play session. State is reset when you stop and start play mode.