I’m a bit stuck on this simple concept. Here’s the scenario:
I have a blueprint class called ‘Door’, of which there is a single instance in the level called ‘MyDoor’. Inside the BP class is a integer variable called ‘DoorState’. I wish to display this door state value on the UI.
I have a BP widget for the UI and am trying to access the door state value form the Door BP, but I am not sure where I am going wrong. What do I put on the Object pin of this Cast node to be able to access the Door BP? Or am I completely wrong in this approach?
This is exactly what I did. I used GetAllActorsOfType (Door) and created the reference using the zeroth element of the return array. As you say, it works but if I have 50 doors the solution is not very scalable. I will conduct additional research regarding your other suggestions.
Is there no way to cast directly to the BP Class instance?
You need to get the door object. You are casting nothing, so it’s going to fail.
There are many way’s to do it, it is your design choice.
A bad way to do it is to Get All Actors of type, with type being your door, and then use the 1st one. That’s really bad but will work.
The way I would suggest you do it is make a GameInstance or GameState Blueprint, and in that make a variable of type door. Then on the BeginPlay in the LevelBlueprint set the door in the level to the variable in the GameState. Then in your UI Get the GameState ( because it’s available everywhere ) and then cast the GameState to your type of GameState and get the door variable off of it.