# How to cast in cpp

**URL:** <https://forums.unrealengine.com/t/how-to-cast-in-cpp/442247>\
**Category:** Blueprint\
**Tags:** oncomponentbeginover, casting, unreal-engine, UE4, CPP, Blueprint, question\
**Created:** [January 28, 2019, 7:27pm UTC](https://forums.unrealengine.com/t/how-to-cast-in-cpp/442247 "2019-01-28T19:27:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_7e1085d1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7e1085d1](https://forums.unrealengine.com/u/anonymous_user_7e1085d1)\
**Post date:** [January 28, 2019, 7:27pm UTC](https://forums.unrealengine.com/t/how-to-cast-in-cpp/442247/1 "2019-01-28T19:27:54Z")

</div>

Ok so i want to create a moving platform that when the player gets on top of it it starts moving up and when the player leaves the platform is stops moving!  
!

This is the blueprint that i made and i want to make the same thing in cpp

 ![266776-screenshot-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/2/2/022cfb74e4ff3f86260c1124884d6a305a4fef4e.png)

Here is the cpp code. When the player overlaps the trigger it starts moving up but when the player jump off the platform the platform doesn’t stop

 ![266777-screenshot-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/f/a/bfa9e8cd6b528929a816afab6079a4ee73c7d8df.png)

---

<div class="post-metadata">

**Author:** ![MazyModz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MazyModz](https://forums.unrealengine.com/u/MazyModz)\
**Post date:** [January 29, 2019, 5:12pm UTC](https://forums.unrealengine.com/t/how-to-cast-in-cpp/442247/2 "2019-01-29T17:12:55Z")

</div>

I’ve had issues using the Shape Component’s Overlap Event signatures in C++.

My solution was to use the actor Begin and End overlap events. Try this:

```
// MovingPlatform.h

virtual void NotifyActorBeginOverlap(AActor* OtherActor) override;
virtual void NotifyActorEndOverlap(AActor* OtherActor) override;

// MovingPlatform.cpp

void AMovingPlatform::NotifyActorBeginOverlap(AActor* OtherActor)
{
    Super::NotifyActorBeginOverlap(OtherActor);
    if (Cast<AFP_FirstPersonCharacter(OtherActor))
    {
        bMoveUp = true;
    }
}

void AMovingPlatform::NotifyActorEndOverlap(AActor* OtherActor)
{
    Super::NotifyActorEndOverlap(OtherActor);
    if (Cast<AFP_FirstPersonCharacter(OtherActor))
    {
        bMoveUp = false;
    }
}

```

These functions will be called when ANY component was overlapped in your actor.

I had a similar situation when I was making Capture Points and the Shape Component’s Overlap Event Signatures did not execute, so I solved it by using these functions.

Let me know if it helps!

~ Dennis “MazyModz” Andersson

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7e1085d1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7e1085d1](https://forums.unrealengine.com/u/anonymous_user_7e1085d1)\
**Post date:** [January 29, 2019, 8:08pm UTC](https://forums.unrealengine.com/t/how-to-cast-in-cpp/442247/3 "2019-01-29T20:08:22Z")

</div>

Yes thank you that works! But i have some questions

1. Why we have to define that its virtual void and its override?
2. Why do we have to type Super::NotifyActorBeginOverlap?
3. Every component on the AMovingPlatform class that has a collision volume and it gets overlapped it is gonna trigger that event?

---

<div class="post-metadata">

**Author:** ![MazyModz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MazyModz](https://forums.unrealengine.com/u/MazyModz)\
**Post date:** [January 29, 2019, 9:49pm UTC](https://forums.unrealengine.com/t/how-to-cast-in-cpp/442247/4 "2019-01-29T21:49:48Z")

</div>

A virtual function mean that it can be overriden in a derived / child class.

In this case NotifyActorBeginOverlap and NotifyActorEndOverlap is defined in AActor. So in order to change the logic of those functions in your child class you can override it providing it’s marked virtual.

Super::NotifyActorBeginOverlap means that we are executing all functionality that was defined in the parent AActor implementation. This is to prevent ‘loosing’ anything that happens in the parent AActor implementation.

And finally yes, if anything overlaps any component in your platform actor that is set to overlap, those functions will be called.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7e1085d1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7e1085d1](https://forums.unrealengine.com/u/anonymous_user_7e1085d1)\
**Post date:** [January 29, 2019, 9:51pm UTC](https://forums.unrealengine.com/t/how-to-cast-in-cpp/442247/5 "2019-01-29T21:51:31Z")

</div>

Okay, thank you man!

---

<div class="post-metadata">

**Author:** ![JoSf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JoSf](https://forums.unrealengine.com/u/JoSf)\
**Post date:** [January 30, 2019, 12:44am UTC](https://forums.unrealengine.com/t/how-to-cast-in-cpp/442247/6 "2019-01-30T00:44:33Z")

</div>

Unless I am wrong, in this instance, calling Super:: doesn’t do anything else than call a possible derived blueprint event of OnBeginOverlap? Seems that in most cases you’d prefer not to call it, because that event fires on its own as well, and calling the Super:: on C++ side will mean that the event will fire twice.
