Archive 17/01/2023.

[Solved]Component in Node, lost in Event

rbnpontes

Hello Guys, i have a problem when i’m trying to get component in node with custom event.
The component is lost.
Sorry for my english

jmiller

Hello,

Your english is fine, what I do not understand is the problem. :slight_smile: Can you provide a bit more information or code?

rbnpontes

OK, this is a example of my code

//Part 1
VariantMap& eventHandler = GetEventMapHandler();
eventHandler[RP_MY_EVENT_NODE] = node; 
SendEvent(RP_MY_EVENT,eventHandler);
// This part working with success
//Part 2
Node* _node = static_cast<Node*>(eventHandler[RP_MY_EVENT].GetVoidPtr());
// The casting is working, the Node not return empty but
// If i'm try this
StaticModel* model = _node->GetComponent<StaticModel>();
// The variable model is only null, if i'm trying to get component, The return value is only null
//I'm trying to diferents casts like, static_cast,dynamic & reinterpreter and not working
jmiller

I use static_cast in the same way with success. As you say, Node is saying it has no component of that type. It may help to see how you added it to the Node.
For reference, many samples do this (like 18_Characterdemo).

Modanung

It seems to me RP_MY_EVENT could use an appended _NODE at the beginning of part 2.

rbnpontes

My Node have a StaticModel component

rbnpontes

No, The Component is not removed
I’m added component like this

Node* node = _scene->CreateChild("Test");
StaticModel* m = node->CreateComponent<StaticModel>();
Lumak

As Modanung mentioned, change:
//Part 2
Node* _node = static_cast<Node*>(eventHandler[ RP_MY_EVENT ].GetVoidPtr());

to:
//Part 2
Node* _node = static_cast<Node*>(eventHandler[ [color=#FF0000]RP_MY_EVENT_NODE[/color] ].GetVoidPtr());

rbnpontes

Sorry Guys for the error, i’m added node to Scene and not to Node :laughing:
i’m fixed, thank’s for the help