Jump to content

LUA CPP "how to" 2/7



1) How to get objects created on the editor from Cpp


Easy as it seems, getting an editor created object from cpp code is done basically looping on the entities collection, but there are some things that is good to know.


First one simple way of doing it:


System::Print("start scanning....");
for (auto iter = world->entities.begin(); iter != world->entities.end(); iter++)
  Entity* entity = *iter;
  if (entity->GetKeyValue("name") == "findMe"){
    System::Print(" found entity findMe !!!");
    if (entity->script != NULL){
      foundEntity = entity;


It's supposed that you have a map with an entity named "findMe"

if you like you can use: SetKeyValue to give some "custom" attributes to your entities and then

instead of testing by a already existing key like name you may test by any custom key of your's


if (entity->GetKeyValue("room_number") == "8"){
  System::Print(" entity of room 8"+entity->GetKeyValue("name"));
  if (entity->script != NULL){
    foundEntity = entity;


entities collection has all of them, cameras, lights, models, etc but in some particular situations searching for specific class is necessary: cameras, light has special methods and to work properly it's better to use the correct object.


for example to get a camera created on the editor you may:


//now look for the editor camera:
for (Camera* e : world->cameras)
  if (e->GetKeyValue("name") == "EditorCamera"){
    camera = e;
    System::Print("found editor camera");


note "camera" is declared on app.h as: Camera* camera; so it's a global already defined


that's it, so simple, he?


Next, Back


Recommended Comments

There are no comments to display.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...