Hello guys , i am trying to make cin pickup system in C++ . It is really easy in blueprints but i am struggling to do same in C++ .
I am using SideScroller template for the game . I was following C++ 3rd Person Battery Collector Power Up Game . I have created a base pickup with which i have derived my coinpickup class and then blueprint .
I want to create a simple coin collect for ex: like in mario , when character overlaps on coin
Coin as an actor, and your actor when get an actor overlapping it in its event beginoverlapp, you will check if overlaped actor is type coin and if so, you will check for the coin amount, destroy the coin actor and add the amount to the inventory/purse. There is a good C++ course for Unreal at Udemy from Tom Looman (former Epic) which cover this and it is at at great discount… US$ 10.00 atm if Im not mistaken.
void ACoinPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
// Other Actor is the actor that triggered the event. Check that is not ourself.
if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr))
// Log events
UE_LOG(LogTemp, Warning, TEXT("Picked up."));
i have set bGenerateOverlapEvents on both character( unreal default character ) and my coin pickup . I have also set Collision preset in my pickup to CharacterMesh
You dont need to set the overlap on both actors! Anything which interacts with your character (pawn) dont need to handle overlapp. Thats because it is too much job make anything aware of your pawn and if you change the type of pawn from 1st person to 3rd person or even flying pawn you will have to code for each actor similar to the coin actor to handle the overlapp.
remove the handling of onOverlapBegin from the coin actor
at the pawn actor you set the onOverlapBegin
you need to check at onOverlapBegin if OtherActor is the type of coin actor. You do this trying to cast OtherActor as the CoinActor. If succeeds, then you can get the amount of coin (you need to create something like this as a variable inside coin actor, so this is not necessary now), put into your pawn inventory and then desctroy the coin actor.
This code is so basic, it is impossible to not make it work. I would strongly recommend achieve what you want in blueprint first if you didn’t and then learn how to do it in C++. The C++ 3rd Person Battery Collector Power Up Game has everything for it to work, instead of battery you will have the coin actor and instead of 3rd person character you will change to the platformer character.
Today is the last day for that course which costs only $10 at Udemy.com, the instructor is Tom Looman, it is at 93% discount, you should consider doing it, all this stuff is covered there + the multiplayer part, all in C++, Im doing it myself just for the multiplayer information.