I created script
character begin overlap{
do something
}
And i want do when i begin overlap i can click on e and pickup something or do something, but i don’t know how to do this, i tried but nothing. Help pls
show the code you made and try to pin point where you think it is failing.
it’s blueprints
i learn c++
Hello there, hope you’re well ![]()
I’ve made this snippet that could help you.
If you have any difficulties, feel free to message me!
So what does the error tell you?
you’ll find it listed under “problems” or you can hover the red squiggle and it will tell you more.
I’m not sure it’s should work i’m just try. It’s says “nonstatic member reference must be relative to a specific object”
I don’t know if you already solved this or not but this one is also a solution you can use.
in your GameCharacter.h, create a variable of AGun* (You can also use another type for the item) and a public setter to set the Gun.
UCLASS()
class YOUR_API AGameCharacter : public ACharacter
{
...
private:
UPROPERTY(...)
class AGun* OverlappingGun;
public:
void SetOverlappingGun(AGun* Gun);
...
}
in the GameCharacter.cpp,
void AGameCharacter::SetOverlappingGun(AGun* Gun)
{
OverlappingGun = Gun;
}
And in the AGun.cpp, in the Begin and EndOverlap, you can set the overlapping gun of the character there.
void AGun::OnBeginOverlap(....)
{
// Make sure the one who overlap is the character
AGameCharacter* Char = Cast<AGameCharacter>(OtherActor);
if (Char)
{
Char->SetOverlappingGun(this);
}
}
void AGun::OnEndOverlap(....)
{
// Make sure the one who overlap is the character
AGameCharacter* Char = Cast<AGameCharacter>(OtherActor);
if (Char)
{
Char->SetOverlappingGun(nullptr);
}
}
Lastly, you just need to check the OverlappingGun value in the PickUp() function (dont forget to also bind the PlayerInput).
void AGameCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
// Set up gameplay key bindings
check(PlayerInputComponent);
PlayerInputComponent->BindAction("PickUp", IE_Pressed, this, &AGameCharacter::PickUp);
}
void AGameCharacter::PickUp()
{
// Check if there is overlapping gun
if (OverlappingGun)
{
// Pick up the gun
}
}
you can just put your pickup logic inside the PickUp() after checking if OverlappingGun is valid.