Menu
Lumberyard
Developer Guide (Version 1.11)

Linking Entities

CryLua is deprecated and will be removed in a future version of Lumberyard.

Note

This page contains information on using Lua scripting to work with the legacy Entity system. These Lua scripts use the legacy script context. Starting with Lumberyard 1.8, Lua scripts use the new behavior context that replaces the legacy script context. Scripts that were written before the integration of the behavior context no longer work in Lumberyard versions 1.8 and later. For information on updating Lua code from legacy script context to the new behavior context, see the migration notes for Lumberyard 1.8. For information on using Lua with Lumberyard's new component entity system, see Writing Lua Scripts for the Component Entity System.

In Lumberyard Editor, you can link an entity to other entities. These links are organized inside the Entity system. Each entity can link to multiple entities. Each link has a name associated to it. See the Amazon Lumberyard User Guide for more information about grouping and linking objects.

The following example Lua script searches the Entity system for any links to other entities that are named "Generator".

Copy
function RadarBase:IsPowered() local i=0; local link = self:GetLinkTarget("Generator", i); while (link) do Log("Generator %s", link:GetName()); if (link:GetState() == "PowerOn") then if (link.PowerConnect) then link:PowerConnect(self.id); return true; end end i=i+1; link=self:GetLinkTarget("Generator", i); end return false; end

The legacy ScriptBind functions related to entity links are listed in Lua ScriptBind Reference. The following functions are used to read or create entity links:

  • CountLinks

  • CreateLink

  • GetLink

  • GetLinkName

  • GetLinkTarget

  • RemoveAllLinks

  • RemoveLink

  • SetLinkTarget