How to call a request bus on a system component from Lua

0

Hi Guys,

Trying to write a demo for my eye tracking gems, and I am just going around in circles.

I have tried various technologies, but due to what assets I have available I am trying to add my stuff to the simple Jack locomotion demo. I do not want to modify the c++ code at all. I can call all the methods from c++, but to me a gem (basically a plugin) should not require c++ changes to function. You can choose to make those changes and all is fine, I just don't believe I should force you to change game code.

All I need to do is call a function that is defined on my ebus from Lua.

I have checked that the samples project now has my new system components active.

Then I added a call to the function as follows

TobiiInteractionRequestBus.Event.PerformRayCast();

The TobiiInteractionRequestBus is nil, so that doesn't work.

I dug around in the forums and tried to add my code to the AZ::BehaviorContext , but it won't compile complaining about needing AZ_RTTI. I tried to add AZ_RTTI_INFO to the class, but then it fails to compile saying AZ_RTTI has already been defined. (Probably in the AZ_COMPONENT macro)

I tried creating a handler in lua, no dice.

So I am out of ideas.

Anybody know what I should do?

asked 6 years ago201 views
9 Answers
0
Accepted Answer

Hi Guys,

Well got it working.

Sort of.

I use CVars for debug displays, so tobii_show_ray 1 displays the eye ray for the interaction gem and shows any entities that intersect the ray.

Except the console is not available when the component is created.

I allowed for that in the activation code, but forgot it in the actual debug code.

So it was try to read from a null pointer, which is why the editor was crashing.

(Found the crash dump eventually in dev\cache.... not where I was expecting it)

So I now have a working system, except ..... debug display does not work in the editor, and I cannot figure out how to run the standalone game with a particular map. Well not at this time on a Friday anyway.

Cheers guys, thanks for the help

answered 6 years ago
0

Not sure what the exact cause is, without looking at your actual code, but typically event commands in Lua require an EntityId() as their first argument:

TobiiInteractionRequestBus.Event.PerformRayCast(self.entityId);
--If operating on this object that has this component on it

If you built this from Lumberyard (using their Create Gem thing in the Project Configurator), and didn't modify the AZ::EBusAddressPolicy HandlerPolicy/AddressPolicy to ById (in <GemName>Bus.h), then your EBus should have Single for that value, and your call in Lua would be

TobiiInteractionRequestBus.Broadcast.PerformRayCast();

If you have changed this value, then I can't help you (I have no experience creating a Gem with multiple handlers. Sorry.).

I have only had to use the AZ_RTTI/AZ_TYPE_INFO methods to a class that I wanted to serialize (this was automatically provided for the Gem EBus in the <GemName>Module.cpp)

EDIT: Do you see your EBus in the Lua Editor? If not, then you might not be serializing correctly.

answered 6 years ago
0

Well I have made some progress.

I went back to the start and tested after adding each line of code.

This showed that the class that required RTTI info was not my system component, but the structure I was returning from the PerformRayCast method.

So I can now add things to the behaviour context

So I tried this ...

				behaviourContext->EBus<TobiiInteractionRequestBus>("TobiiInteractionRequestBus")
->Attribute(AZ::Script::Attributes::Category, "Tobii")
->Event("PerformRayCast", &TobiiInteractionRequestBus::Event::PerformRayCast);

When I try to call this as an event from lua I get a message saying that TobiiInteractionRequestBus.Event is nil

So I tried calling broadcast instead, and the editor crashed.

Well at least lua can find the requestbus now......

So next I tried

behaviourContext->Class<TobiiInteractionSystemComponent>();
behaviourContext->Class<TobiiInteractionSystemComponent>("TobiiInteraction")
->Method("PerformRayCast", &PerformRayCast, NULL, "Tobii interaction perform raycast");

and now I get an error

attempt to index global 'TobiiInteraction' (a nil value)

So I guess there is something else I must add

sigh

answered 6 years ago
0

Hi Roosevelt, yes it's single.

I still think describing crashing the editor as good may be a bit of a stretch though ;>

answered 6 years ago
0

Hi Roosevelt,

Thanks for getting back to me.

The actual error is ...

attempt to index global 'TobiiInteractionRequestBus' (a nil value)<br>

So adding the entity ID is not going to help. ( I did try it though, made no difference )

In the editor the classes reference panel is empty. Nothing in it at all. Not even the ones I know are working.

Trying the Broadcast made no difference either.

I guess I need to find a way to add it to a behaviour context before lua can see it, but that is looking impossible

Cheers

Paul

answered 6 years ago
0

I don't have anything other than LuaIDE (0xfffffff) in the target drop down.

Even when the editor is running.

answered 6 years ago
0

@REDACTEDUSER

Glad to hear you made progress! For launching a particular level, you will need to either create a shortcut to your level or launch it from a bat file with +map mapname (see information here towards the bottom).

start release_directory\launcher_executable_name +map level_name

Or, in the case of the Windows shortcut, modify the Target in the shortcut properties to:

C:\Path\to\game\launcher\gameLauncher.exe +map level_name

I personally use the shortcut method, and have found that it works for Profile and Release Builds.

answered 6 years ago
0

@REDACTEDUSER

If the entire panel is empty, then I think you might not have selected the target for the Lua Editor. Up towards the top of the Lua Editor, on the right of the tool bar, there should be a button for "Target." You want to make sure that the target is set to the non-FFFFFFFF value (Project Configurator on my end). This requires the Lumberyard Editor to be running to work.

REMOVEDUPLOAD

answered 6 years ago
0

@REDACTEDUSER

Crashing is good in this case! That probably means that it found your EBus when you ran the broadcast version, ran your PerformRayCast method, and then crashed as a result. Can you confirm that the HandlerPolicy and AddressPolicy in your TobiiInteractionBus.h (the file in your gem's Code/Include folder by default) has AZ::EBusHandlerPolicy::Single for both of those values (see the information here towards the bottom)? If it is single, you should call Broadcast in Lua.

answered 6 years ago

This post is closed: Adding new answers, comments, and votes is disabled.