How to cast to actor?

Hello. I have 2 classes: Character and Door. How to cast to Door Actor in Character using C++? I dont understand what write in brackerts.

void AMyProject2Character::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);
    if(Open)
    {
	    AMyDoorActor MyDoor = Cast<AMyDoorActor>(IDontUnderstandWhatToWrite);
        MyDoor->ToggleDoor();
    }
}

Ok, i need to write AMyDoorActor* MyDoor = Cast(IDontUnderstandWhatToWrite); but what i need to write in brackerts?

You need an object reference of the type AMyDoorActor or the Cast will fail.

When you call Cast it is like saying “I have this object and I know it is of type AMyDoorActor, please let me use it as such”.

Note that if the Cast fails the game will crash unless if you check if MyDoor is not a nullptr before using it. If you want the game to crash if it is null you can use CastChecked instead.

The explanation of GarnerP57 is correct.

AMyDoorActor MyDoor = Cast<AMyDoorActor>(IDontUnderstandWhatToWrite);
         MyDoor->ToggleDoor();

IDontUnderstandWhatToWrite should be a AMyDoorActor Object Reference. That means you need to have a reference to the door that you want to open or close. So something like:

AActor* theDoorInTheWorld = GetDoorFromWorld(); 
AMyDoorActor* MyDoor = Cast<AMyDoorActor>(theDoorInTheWorld );
             MyDoor->ToggleDoor();

I don’t know how you get the door in your situation. Does the character have the door variable already?
Or do you need to get it from the world? any further information will be helpfull.

Now it looks like you are opening a door if a variable ‘open’ is true. If you just want to open a door once a variable turns true, you should not check that in the Tick function. You should put as least code as possible in the Tick function.
You should call the ToggleDoor function after changing the door variable.

Thank you for you answer, I created c++ class MyDoorActor and place it in the world.