Reputation: 31
I recently switched from unity and I wanted to know if there was a “getComponent” equivalent in UE4? I have an enemy script and I created a blueprint from that script and have added a widget with a progress bar to show the enemies health during combat. I have seen a lot of examples of how to do this in blueprint but if possible, I would like to just do it in code and let the percentage be calculated when it is needed to be, like after damage or something, rather than binding via blueprints.
I have tried using the getcomponentbyclass method but that throws an error because the component I want is not a child of the actor class.
Any help appreciated
Upvotes: 3
Views: 4839
Reputation: 4817
You need to call GetComponentByClass()
on an Actor
.
If your Enemy
is a Component, you can call getOwner()
to retrieve the actor owning this component.
You can then call GetComponentByClass()
on this actor instance.
Upvotes: 2