Skip to content

Signals

Mikulas Florek edited this page Jul 15, 2024 · 2 revisions

Signals can be used to connect events and functions - e.g. call a function when user clicks on a button.

To do this, simply add Core / Signal component to an entity and set event and function to desired values.

image

All events on modules registered in reflection system (e.g. by using LUMIX_EVENT macro) can be used as a source.

image

All functions on modules registered in reflection system (e.g. by using LUMIX_FUNC macro) can be used as a destination.

image

Parameters in source and destination must match. Signal is assigned to an entity, i.e. the function is called only if event is triggered on registered entities. You can connect multiple signals to the same destination.

Example

Let's assume you want to react to user clicking on a button. There's already an event for that GUIModule::buttonClicked(EntityRef e).

  1. In a module (e.g. your GameModule) create a function void GameModule::connectClicked(EntityRef e)
  2. register the function in reflection system: LUMIX_MODULE(GameModule, "myplugin").LUMIX_FUNC(connectClicked)
  3. create an entity with a gui button
  4. attach a signal component to the button entity
  5. in property grid set signal's event to GUIModule::buttonClicked and function to connectClicked
  6. observe that GameModule::connectClicked is called every time users clicks on the button
Clone this wiki locally