Skip to content

Native Scripting

Dorvann edited this page May 5, 2025 · 1 revision

Native Scripting Plugin

The Native Scripting plugin provides a way to write scripts in C++ associated with the engine.

Scripts

Scripts allows the user to write their own logic inside three functions available:

  • OnCreate: Called at the initialization of the engine
  • OnUpdate: Called at each frame while the engine is running.
  • OnDestroy: Called right before the engine shuts down.

Each function accepts the engine core as parameter.

Class architecture

Each script has to follow a specific class architecture and thus can not be customized. Scripts must inherit from the ScriptableEntity class and contain the three functions mentioned above, missing one of them is not supported.

The minimum required architecture is the following:

#pragma once

#include "ScriptableEntity.hpp"

class exampleScript : public ES::Plugin::NativeScripting::Utils::ScriptableEntity
{
    public:
        void OnCreate(const ES::Engine::Core &)
        {
        }

        void OnUpdate(const ES::Engine::Core &)
        {
        }

        void OnDestroy(const ES::Engine::Core &)
        {
        }
};

Linking the script

The NativeScripting component needs to be added to the entity in order to bind the script to it:

ES::Engine::Entity exampleEntity = core.CreateEntity();
exampleEntity.AddComponent<ES::Plugin::NativeScripting::Component::NativeScripting>(core).Bind<Game::Script::exampleScript>(core);

In order to keep updating all the scripts while the engine is running, the NativeScripting plugin provides the system function to update the scripts internally, as everything is handled by the engine.

The UpdateScripts system class be registered like any other systems like so:

core.RegisterSystem<ES::Engine::Scheduler::RelativeTimeUpdate>(ES::Plugin::NativeScripting::System::UpdateScripts);

This will ensure that all the scripts will update during the game loop.

Clone this wiki locally