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.
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:
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.