Access to "Owning Entity" from component?

Say I have a component handle:

Entity * e1;
ComponentHandle<ComponentType1> handle = e1->component<ComponentType1>();

I’d like to get the orignal entity from the component handle, such as:

Entity * e2 = handle->GetOwningEntity();
e2 == e1

Is this possible in EntityX? A workaround I could think of is having:

struct ComponentType1 : public Component<ComponentType1>
{
    ComponentType1();
    ComponentType1(Entity * e) : self(e) {}

    Entity * self;
}

And then always calling such as:

Entity * e1;
ComponentHandle<ComponentType1> handle = e1->component<ComponentType1>(e1);

Is there a more structured way to do this?

Thanks in advance!

There’s a ComponentHandle::entity() method, is that what you’re looking for?

By the way, components don’t need to inherit from Component<>. You can use any type as a component directly.

1 Like

Yes, this sounds like what I was looking for. Thanks for this.