C++ Event Bus "Nil" in LUA

First, I created an event bus (EBus) interface with two functions in C++, implemented that EBus interface and its two functions using “Reflect” and “behaviorContext” in another class, updated my “waf_files”, and built my application.

Next, in the editor, I have a UI Canvas button that uses a LUA script to call one of my EBus functions using “MyEventBus.Broadcast.CreateCanvas()” when the button is clicked. I am following the “LyShineExamples” project in the Gems folder since it programmatically modifies the UI.

When I click the UI Canvas button, I get the error: “attempt to index global ‘MyEventBus’ (a nil value)’”.

Why does UI Canvas not recognize the “MyEventBus” EBus?
Any ideas on how I can troubleshoot this problem?

What is the HandlerPolicy and AddressPolicy for the Ebus?

Hi @XGibbousX,

From the sounds of things it seems like you might be trying to access a global EBus by Id when it doesn’t have one.

A global EBus is like a singleton, there’s only one of them, and you just access it by using YourRequestBus::Broadcast(&YourRequestBus::Events::FunctionOnYourBusInterface); as opposed to YourRequestBus::Event(TheBusId, &YourRequestBus::Events::FunctionOnYourBusInterface);

(The significant difference being Broadcast and Event).

If you could paste some snippets I can try take a closer look and see if I can spot what’s going on.



Update: As @ravenboilinux rightly points out this will be determined by the HandlerPolicy and AddressPolicy, you can find these by looking at the bus you’re inheriting from. (Is it just AZ::EBusTraits or maybe AZ::ComponentBus? - the first by default will be a global bus unless you set the handler policy and id, AZ::ComponentBus uses AZ::EntityId as an address to refer to individual Entities.

1 Like

@tom-hh you hit the nail on the head in what I was thinking. I was trying to see if the EBus was a global EBus or not. Question: What does E in EBus strand for?

1 Like

@ravenboilinux No worries! :slight_smile: Haha I think it’s just short for Event :stuck_out_tongue: Though the terminology does all get quite confusing at times :see_no_evil:

Also for reference there’s quite a lot of good info about EBuses on this page and its sub-pages - Working with the Event Bus (EBus) system - Lumberyard User Guide (e.g. Event Buses in Depth - Lumberyard User Guide and Usage and Examples - Lumberyard User Guide)

This page that’s also a bit buried has got some great info on best practices too - Components and EBuses: Best Practices - Lumberyard User Guide

I hope that’s some help @XGibbousX too!



Hi XGibbousX,

one thing I would suggest is checking whether your bus is actually getting reflected. If you put a breakpoint inside your Reflect function you can see if it’s being called. I’ve lost count of the number of times I’ve added something and forgotten to reflect it, then wondered why it wasn’t working.

Best wishes,


1 Like