OnEventBegin Always Called with "(a userdata value)"

I’m having an issue using GameNotificationBus. The OnEventBegin event is being called but the data I’m attempting to pass through it isn’t coming through. The function is being called with “(a userdata value)” according to the debugger.

Here is the relevant code:

sender entity:

self.pitchNotificationId = GameplayNotificationId(self.entityId, "pitch", "float");
GameplayNotificationBus.Broadcast.OnEventBegin(self.pitchNotificationId, 10);

receiver entity:

self.pitchNotificationEventId = GameplayNotificationId(self.entityId, "pitch", "float");
self.pitchNotificationHandler = GameplayNotificationBus.Connect(self, self.pitchNotificationEventId);

...

function camera:OnEventBegin(pitchDelta)
if GameplayNotificationBus.GetCurrentBusId() == self.pitchNotificationEventId then
   if(pitchDelta == 10) then
		Debug.Log("correct value");
	  else
		Debug.Log("incorrect value");
  end
	
end

And I get the error message:

incorrect value

Is there something wrong with this script? Why does it seem like everything I send through GameNotificationRequestBus ends up being a userdata object?

The gameplay notification bus was always finicky is a piece left over from the Cryengine Fork, this has since been replaced with script events which are much more powerful and extendable and it is also exposed to lua.

This system will also be deprecated out of the engine at some point so i wouldnt bother with it.

Where can I find information about using script events in lua?

Ok. Once again, I posted too soon. I eventually figured this one out.

For anyone that’s interested, there were two problems with the script code I posted.

For the sender entity, I was passing self.entityId as the first parameter which will only send the message to other scripts attached to the current entity. In this example, I was attempting to send the message to a script attached to a different entity so I needed to pass that entity’s ID as the first parameter.

self.pitchNotificationId = GameplayNotificationId(self.Properties.CameraId, “pitch”, “float”);

I had actually already tried this before and I still wasn’t getting the correct result because of the second problem. GameplayNotificationBus.Broadcast doesn’t seem to work as I expected. I changed Broadcast to Event and everything finally worked.

GameplayNotificationBus.Event.OnEventBegin(self.pitchNotificationId, 10);

1 Like