Actor References in Widget

So my intention right now is to have enemies spawn on a map and when you hover over the enemy it will display their name. I have different enemy classes inheriting off of a base enemy class that holds the code to make this happen.

	PrimaryActorTick.bCanEverTick = false;

	CharacterCapsule = this->GetCapsuleComponent();
	CharacterCapsule->OnBeginCursorOver.AddDynamic(this, &AEnemyBase::StartCursorHover);
	CharacterCapsule->OnEndCursorOver.AddDynamic(this, &AEnemyBase::EndCursorHover);

Once needed the enemy will spawn and things happen. The confusing part for me is the code works perfectly fine for only one enemy. I am new to inheritance and all that at the moment but my understanding is all the children should get the same code and run identically. But regardless of the spawning method it only works for one of the enemies and not the others. I checked the collision for the capsule and everything matches and should work as well but it doesn’t and I am a it lost.

I think I figured out that the issue is with my widget not my class itself. Due to the way I am creating the reference for the enemy base the reference is only setting for the first instance of it that appears in the array. What would be the best way to set up the reference so that it would be able to communicate with all the enemies not just the first?

Store entire array in variable, then you can either use “For Each” to loop the code on each array element or if you single function node you plug array to “Target” pin and it will be executed on all array elements.

Here also hint, you can make C++ class of UUserWidget and create Blueprint (not Widget Blueprint) out it, when you do that blueprint actually will open as widget blueprint and will be based out of UUserWidget. This will help you with C++ to UI communication as now you can make BleuprintImplmentableEvent on that UUserWidget class which you can call in C++ and fire events in widget blueprint, you only need pointer to it and you can do this by initiating HUD in C++:

HUD = CreateWidget<UMyUserWidget>((), MyHUDClass, FName("HUD"));
if(HUD) HUD->AddToViewport();

HUD is property you declare in PlayerController for example, MyHUDClass is TSubclassOf<UMyUserWidget> EditDefaultOnly property which contain class oh HUD that you will set in blueprint. Now you can make BlueprintReadWrite array in the your UUserWidget class and make enemies register themselves by adding themselves to that array