I’ve set up a door that closes on a timer but I’m struggling to display the timer in a widget
I know how to cast to the player character & how to cast to the game mode, but I have no idea how to cast to an actor blueprint properly
When you cast to anything, you need to get a valid reference first. For your bp_shutter, you need to get a reference to that actor you’re trying to get DSeconds from. You can do this in many ways, check out my recent answer here to show a few ways to get references for casting. It all depends on how your game is setup.
You need to get a reference to the bp_shutter into your widget (i.e. the widget needs to know the door.).
Adding a new variable of type bp_shutter named ShutterRef would be the first step.
It now depends on where your widget is embedded. Is it part of your HUD or owned by a widget component? I assume the HUD:
on your HUD you need to create a variable named TimerWidget of type of your widget blueprint type. This variable must be set when the widget is created and added to screen.
You could then add to your begin play in your bp_shutter something like:
GetHUD
Cast to your HUD type
GetTimerWidget
SetShutterRef
I hope this helps getting an idea what has to be done, it is difficult to suggest the correct solution without seeing all of your project.
This is something that I struggled with for a long time as well. For me it was because I thought casting was the only way to communicate with other actors which isn’t the case. In your situation, rather than casting to the player, it would better serve you to implement all of the functionality you want inside a door blueprint. There’s no need to set up the timer elsewhere. Then you can create an “Interact” key inside of your character and cast from the door to the character - which you pointed out is easy to do. Just as a quick mention, you can also use “Get all actors of class” to grab your door and not need to cast to anything or even use a Blueprint Interface to communicate between your blueprints.
I’ve created a video tutorial that goes over how to set up interactable objects that could help you a lot. If you want the door to be timer based and triggered in the level, this should still help you.