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
[Solved]Component in Node, lost in Event
Hello,
Your english is fine, what I do not understand is the problem. Can you provide a bit more information or code?
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
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).
It seems to me RP_MY_EVENT could use an appended _NODE at the beginning of part 2.
My Node have a StaticModel component
No, The Component is not removed
I’m added component like this
Node* node = _scene->CreateChild("Test");
StaticModel* m = node->CreateComponent<StaticModel>();
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());
Sorry Guys for the error, i’m added node to Scene and not to Node
i’m fixed, thank’s for the help