Behaviours

All behaviours created with behaviour() can access the following member and implement the following callback functions.

Members

Member

Description

script

A ScriptedBehaviour

targets

A list of objects assigned in the Unity Editor

gameObject

The GameObject on which this Ravenscript resides

transform

The GameObject’s Transform component

ScriptedBehaviour script

The ScriptedBehaviour component in which the Ravenscript is executed.

table targets

A Lua table with references to other Unity objects such as GameObjects, Transforms, and prefabs. These targets are assigned and named in the Unity Editor.

-- In this example a UiCanvas is stored under the name `canvas`. It was
-- assigned in the Unity Editor.
self.targets.canvas.gameObject.SetActive(true)

-- We can also print all stored targets:
for key,value in pairs(self.targets) do
        print(tostring(key) .. " = " .. tostring(value))
end
GameObject gameObject

The script’s GameObject. Use primary to access the GetComponent() method.

Transform transform

The GameObject’s Transform. Used to translate, orient, and scale the object.

Callback methods

Method

Description

Awake()

Called once

Start()

Called once

Update()

Called every frame

LateUpdate()

Called every frame after animations and game logic update

FixedUpdate()

Called every time the physics engine updates, typically used for applying forces over time

OnAnimatorIK()

Called every time the animation engine updates, typically used for updating animation IK targets

OnEnable()

Called when the ScriptedBehaviour is enabled (from activating its GameObject)

OnDisable()

Called when the ScriptedBehaviour is disabled (from deactivating its GameObject)

OnDestroy()

Called when the ScriptedBehaviour is destroyed

void Awake()

Called once when the Ravenscript component is instantiated. Use Awake() to store references to other Ravenscripts and Components. Use Awake() for setup and initialization of internal variables.

function Rachael:Awake()
        self.line = self.gameObject.GetComponent(LineRenderer)
end

Awake() is called prior to Start(). Awake() is called if-and-only-if its GameObject is active.

void Start()

Called once when the Ravenscript component is instantiated. It should be safe to interact with other components and scripts which references you gathered in Awake().

function Rachael:Start()
        local p = Vector3(0, 0, range)
        self.line.SetPosition(1, p)
end

Start() is called after Awake(). Start() is called if-and-only-if its GameObject is active.

Many developer use Start() exclusively and ignore Awake(). Reserving the use of Awake() solely to solve order dependent initialization problems.

void Update()

Called once every frame. The bulk of all game logic goes here.

function Rachael:Update()
        local position = self.transform.position
        position = position + Vector3.one * Time.deltaTime
        self.transform.position = position
end

Update() is called after Start(). Update() is called if-and-only-if its GameObject is active and enabled.