Generate collision events when a key is pressed

Hello,
My name is Luis Filipe and I have been working a Top-Down Arena Style hoard mode game for an assignment, it is a C++ project and I am not allowed to use blueprints.
I have a PickupActor class that should be added to the players inventory component when the “E” key is pressed. To accomplish that I wanted to have a USphereComponent in my Character class that when I press the “E” key would either activate or call a function that generates the collision events that frame. Since some items may already be inside the the sphere when the “E” key is pressed I can’t use the Begin or End overlap events.

One solution I have considered is registering the begin and end overlaps of all pickups by adding and removing their pointers to a map, but that sounds very bad.

Anyone know if there is a way to generate the overlap events this frame for all objects currently overlapping with the Component?

if you were using blueprints (i know you cant but theres C++ behind it) i would suggest the get overlapping actors node. then you could run a loop to check for any actors of your pickup class and add it to your inventory. I dont know c++ but i know anything you can do in blueprint is implemented from C++ its just a matter of finding the right script so it shouldnt be too much trouble to figure out.

So I am currently trying to make this work, but the GetOverlappingActors returns an empty array…

Here is the generation of the components that should interact with one another:

In PlayerCharacter:

APlayerCharacter::APlayerCharacter()
{
        m_PickupReach = CreateDefaultSubobject<USphereComponent>("Pickup Reach");
        m_PickupReach->SetSphereRadius(100.0f);
        m_PickupReach->SetRelativeLocation(FVector(0.0f, 0.0f, 90.0f));
        m_PickupReach->SetupAttachment(RootComponent);
        m_PickupReach->SetGenerateOverlapEvents(true);
        m_PickupReach->SetCollisionProfileName("OverlapAllDynamic");
        m_PickupReach->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
}

void APlayerCharacter::InteractWithActors()
{
    TArray<AActor*> OutActors;
    TSubclassOf<AActor> ClassFilter;
    m_PickupReach->GetOverlappingActors(OutActors, ClassFilter);

    for (int i = 0; i < OutActors.Num(); i++)
    {
        AInteractableActor* interactableActor = Cast<AInteractableActor>(OutActors[i]);
        if (interactableActor)
        {
            interactableActor->Interact(this);
        }
    }
}

In IteractableActor:

AInteractableActor::AInteractableActor()
{
        m_InteractBounds = CreateDefaultSubobject<USphereComponent>("Interact Bounds");
        m_InteractBounds->SetupAttachment(RootComponent);
        m_InteractBounds->SetGenerateOverlapEvents(true);
        m_InteractBounds->SetCollisionProfileName("OverlapAllDynamic");
        m_InteractBounds->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
}

Basically PlayerCharacter::InteractWithActors never enter the for loop because OutActors is empty.

hmmm the script looks good from what i can tell though i dont know C++ or the ue4 api so thats not saying much.

one thing i noticed that im not sure on is

TArray OutActors;

is there supposed to be an asterisk in there? its supposed to be just an array of actors. now i know the asterisk can be a wildcard in some languages so im not sure on the implication here. again though not a C++ guy and its been awhile since i wrote anything in a actual scripting language.

Yes the asterisk means it is a pointer to the actor not the actual object.
I have fixed it. It turns out you can’t have both of these line at the same time:

         m_InteractBounds->SetCollisionProfileName("OverlapAllDynamic");
         m_InteractBounds->SetCollisionEnabled(ECollisionEnabled::QueryOnly);

Thank you very much for your help Thompson13!

GetOverlappingActors() is a function I can call in the C++ code. It is probably the correct answer. I will test it as soon as possible.