Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Editor Scripting API


Josh

237 views

The Ultra Engine editor is designed to be expandable and modifiable.  Lua script is integrated into the editor and can be used to write editor extensions and even modify the scene or the editor itself in real-time. 

We can create a scene object entirely in code and make it appear in the scene browser tree:

box = CreateBox(editor.world)
box.name = "box01"
o = CreateSceneObject(box) --make editor recognize the entity and add it to the scene browser
o:SetSelected(true)

box.thumb.gif.9b4850b41f8657dc3734bfc4e3428fe9.gif

We can even modify the editor itself and start adding new features to the interface:

editor.sidepanel.tabber:AddItem("Roads")
p = CreatePanel(0,0,300,500,editor.sidepanel.tabber)
button = CreateButton("Create",20,20,100,30,p)

Animation.thumb.gif.daa7db33ae4fa2f037b10692621e44da.gif

Of course, you would usually want to put all this code in a script file and either run the script by selecting the Script > Run Script... menu item, or placing the script in the "Scripts/Start" folder so it automatically gets run at startup. But it sure is cool to be able to experiment live with Lua right in the console and see the result of your code instantly.

  • Like 4
  • Thanks 1

8 Comments


Recommended Comments

This is pretty cool. I have a small suggestion though:

The first scenario you showcased, could leave you with objects, which are not part of the scene-tree, resulting in inconsistent behaviour, if you do not call CreateSceneObject. I would suggest to have a callback-system like a ObjectCreated-hook built into the engine, which the editor then could use to automatically call CreateSceneObject with the new object. It makes for one less gotcha you need to watch for when writing scripts and imho better reflects the intention of the scene-browser as a way to see ALL objects in the scene. Also I can imagine this hook to be beneficial for other use cases.

Of course, there would need to be a way to retrieve the scene-object for a given object, as well, since the user is not generating the element themselves anymore and thus does not have a reference if they need it (e.g. for selecting the object as in the example).

Link to comment

I have thought about this, and I favor making things detailed and explicit. There are reasons for having an entity that does not get recognized by the editor. The little widgets for moving and rotating selected objects are entities, but they don't appear in the scene tree. Neither do the viewport cameras, or the scene grid mesh.

The SceneObject object gets stored in the entity "extra" member, which is just a shared_ptr<Object>, so it can be retrieve if you have the entity.

Link to comment

I would extend the CreateSceneObject function with some kind of key or type element. And also methods to get,filter,iterate and modify all Scene objects of a certain type. This would make something like this possible:

box = CreateBox(editor.world)
box.name = "box"..(GetSceneCountForType("BoxCreator") + 1)
o = CreateSceneObject(box,"BoxCreator") --make editor recognize the entity and add it to the scene browser with a specified key or type
o:SetSelected(true)

 

  • Like 1
Link to comment

Here is a simple example that adds new functionality:

function myfunc() Notify("HI!") end
ListenEvent(EVENT_WINDOWCLOSE,editor.mainwindow,myfunc)

When you close the window a message box is shown.

So you can actually code new features into the editor, as you are using the editor. :cool:

Link to comment

If you want to play a funny joke on someone, tell them to run this script:

function f()
Notify("You cannot close the program!")
return false --cancels the event
end

ListenEvent(EVENT_WINDOWCLOSE,editor.mainwindow,f)

You can even paste it in all as one hilarious line:

function f() Notify("You cannot close the program!") return false end ListenEvent(EVENT_WINDOWCLOSE,editor.mainwindow,f)

Your coworkers will love it!

  • Haha 2
Link to comment
Guest
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...