Understanding Casts
In its simplest form, if your Actor
can be cast to BP_Ladder
, then it will return the casted object on the output pin.
Just to ensure you know how a cast works, I have to point out that you can't cast a given type to some unrelated arbitrary type; it has to be "castable" to the cast destination. So if you think that the Actor
object returned by your overlap is genuinely a BP_Ladder
, or a blueprint class that derives from BP_Ladder
, then you should be OK. But that has to be the case; otherwise it will fail every time.
https://docs.unrealengine.com/en-us/Engine/Blueprints/UserGuide/CastNodes
Sorry if I'm being patronising, but if a cast isn't working 9/10 it hasn't been used correctly.
Debugging
OK that out of the way, if you think you are genuinely casting to the correct type and it's still failing, then you'll need to debug your blueprint with the objective of finding what type is being given to the cast node which results in the failure.
- Select the cast object in your blueprint.
- Press F9 to create a breakpoint; a red circle should appear on the top left of your cast box
- Run your game in PIE mode (Combo next to play, New Editor Window (PIE))
- Put the game in a scenario where your cast will fire (I presume touch the ladder)
- The breakpoint should trigger; your game window will go grey and you'll get a large red arrow pointing down towards your cast box where you placed the breakpoint
- Hover over the
Object
pin on the input side of the cast box. It should show a alt-text containing details of the variable.
- Inside the alt-text box, look for Current value; this should show you the current object type that you are about to cast. You need to ensure that this value is what you expect.
https://docs.unrealengine.com/en-US/Engine/Blueprints/UserGuide/Debugging
Example
I've taken a screenshot of a working game; in this you will see:
- a Breakpoint (the red circle) is shown on the function node (the box)
- the Execution node (red arrow) is
Create Rolling Stock
- the Current value of the variable is
DepotComponent...Depot

Final thoughts
There's a couple of gotchas when using blueprints; one of them in this case could be that you can have two classes with the same name (although they might have different internal "script names" - effectively a fully qualified path). When you debugging an object variable, make sure you match the entire path to the location of your asset in your content folder; this will ensure that you are indeed attempting to cast to the object you think you really are.
Another classic gotcha is "hot reloads". Sometimes the editor needs to reload a module after an on-the-fly build but a class conflict occurs internally; this results in the new version of the class getting a different name (prefixed with HOTRELOADED). Watch out for this; it can cause you to be dealing with two distinct types when casting and you don't even realise. A real sanity-sapper. If in doubt, close and re-open the editor; it fixes it every time.