Call function from RaycastResult->drawable_

My C++ is a bit rusty, so I guess this could be solved by inheritance. I have a class that inherit LogicComponent. This class has a method called “Hit”. The object created by my class is then “hit” by a Raycast that has the result in result->drawable_. This object is a private member of my class.

What’s the best way to handle the scenario: result->drawable_->Hit(…); ?

The class pseudo-looks like this:
class MyClass: public LogicComponent
StaticModel* object;
CollisionShape* shape;
RigidBody* body;

Edit #1: I believe I’ve got this LogicComponent a bit wrong. Guess I should somehow register my class as a component to the engine?

Edit #2: So I’ve tried to understand the LogicComponent structure but I’m not sure how to use it in my case.

My class is like the above but called Chunk, the Chunk class creates my TriangleMesh model and includes the Node/StaticModel/ etc. But I would like to have my Chunk class as a LogicComponent so that I can get my chunk->Update() function automatically called. Not sure if this is a good idea?

Perhaps this is the way to go?

World->nodes[i] = new Node->CreateComponent();
nodes[i]->GetComponent->Init(positionVector3, some_attrs);

Yeah your LogicComponent class is a bit off.
Here’s a simple example on one being made and used :grin:

1 Like

Hehe, thanks! I think I got it now, will have to test it a bit :slight_smile:

If you happen to be using QtCreator you might be interested in these wizards.

I solved it a bit unconventional perhaps. But I create my node, add my class and save a pointer to the node itself in my class. So that the class itself can add rigidbody/trianglemesh to the node.

This way I can build my mesh in the chunk class and still be able to register for Update events etc. This also makes it work in my Raycasting since I can get result->drawable_->GetNode()->GetComponent();

But one thing though. I don’t receive CollisionEvents for node collisions?

In Start() I subscribe to the event:
SubscribeToEvent(GetNode(), E_NODECOLLISION, URHO3D_HANDLER(Chunk, HandleNodeCollision));

For the function:
void Chunk::HandleNodeCollision(StringHash eventType, VariantMap& eventData)

But I never receive any node collision events? The other events such as Update(), Start() etc are called correctly.

Are you sure it isn’t calling correctly? (Maybe adding a breakpoint or log it when it’s called)

From what you’re saying it should work fine unless you don’t have the CollisionShape or RigidBody components created.

haha I found the issue!

I added that to my creation code several days ago since then I thought I didn’t needed any events :stuck_out_tongue:

Thanks for helping out!