[SOLVED] How to send my custom event with - SendEvent

Hi folks!

I’m trying to send global event from blasts or boom fx then it’s almoust end;

and i’m don’t know how to pack Vector3 to my event.

i’m write something but it’s dosen’t work.

this happen then blast must remove, i’m send event.

		SharedPtr<VariantMap> v;

		v["BlastPos"] = GetNode()->GetWorldPosition();
		SendEvent(StringHash("Blast"), v);


Then player got this message he check radius to blast. and if it’s near then player add some shake(noise movements) for your’s camera;

ok now i resolved this,
i’m going to source of engine for looking code like - how to create eventmap parameter and there i found some kind of method - GetEventDataMap();
i’m use it and its works now.

void ScriptFireFx::FixedUpdate(float timeStep)

	float t = animState_->GetTime();
	float l = animState_->GetLength(); 
	if  ( t > l ) 
		using namespace AnimationTrigger;

		VariantMap& eventData = GetNode()->GetEventDataMap();

		eventData[P_DATA] = GetNode()->GetWorldPosition();
		SendEvent(StringHash("Blast"), eventData);



You can actually change:

SendEvent(StringHash("Blast"), eventData);


SendEvent("Blast", eventData);

There is already implicit conversion, so you don’t need to do the conversion to StringHash yourself.

You can also define your own events like so:

#ifndef _GAME_EVENTS_H
#define _GAME_EVENTS_H

#include "Object.h"

	PARAM(P_CHANNEL, Channel);  //int
	PARAM(P_SENDER, Sender);  //string    
	PARAM(P_MESSAGE, Message);  //string   


If I include this, I can call an event like so:

Urho3D::VariantMap map;
map[ServerChatMessage::P_CHANNEL] = channel;
map[ServerChatMessage:] = sender;
map[ServerChatMessage::P_MESSAGE] = message;
//connection->SendRemoteEvent(E_SERVER_CHATMESSAGE, true, map);
1 Like

thank you! it’s very useful example