Jump to content

scene:FindChild()


Rellek
 Share

Recommended Posts

Right, so it's rather easy to find a specific entity in a scene when running a LUA program outside the sandbox editor, i.e.:

 

scene=LoadScene("MyScene")

myobject=scene:FindChild("MyObjectName")

 

It's obviously not that simple to do when running the script from within the Editor, and although I have spent many hours reading through our forums, there still doesn't seem to be a satisfactory answer of doing the same from a LUA script running within the editor, simply because there is no "scene" object to refer to - it's not being loaded anywhere in the code for obvious reasons.

 

So, in short - what object/entity can I refer to in place of the scene to find a specific child entity of the scene by it's name key or am I on the "wishful thinking" track here?

 

Is the scene itself (within the editor) a member of the CurrentWorld() or global framework object for example or do I have to start referring to global classnametables and objecttables to achieve this?

 

All I am really trying to do is to get a reference to a specific directional light within my scene to do some sun path tracking from code running inside the edtor - NOT code using engine.exe from the outside.

 

Assistance from anyone in this matter will be much appreciated.

Link to comment
Share on other sites

The scene object is just a temporary container when loading a sbx file. It should be completely emptied after the scene has been loaded. You don't even always have a scene, for example when you load the scene from a sqlite3 database.

 

After that you can do world:FindChild("name"). Not sure if that works though, since world is not a real entity, but then you have to code that function yourself.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

The scene object is just a temporary container when loading a sbx file. It should be completely emptied after the scene has been loaded. You don't even always have a scene, for example when you load the scene from a sqlite3 database.

 

After that you can do world:FindChild("name"). Not sure if that works though, since world is not a real entity, but then you have to code that function yourself.

 

Nope, unfortunately the entities within the scene (when RUNNING WITHIN THE EDITOR) are definitely not children of the world entity - I have tried that before. Perhaps Josh can tell us how we can access a pointer to a specific entity saved within the sbx file when running the LUA code from within the Editor and don't have a scene=LoadScene("MyScene") entry anywhere in the code.

Link to comment
Share on other sites

require("scripts/linkedlist")

for entity in iterate(fw.main.world.entities) do
if entity:GetKey("name")=="light_directional_1" then
	--Do Something
end 
end

 

Thank's very much macklebee - that worked first time and solved a problem I've been battling with for some time now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   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.

 Share

×
×
  • Create New...