So, I am having a lot of issues trying to get a button press from UMG, to cast to an Actor BP in the level. It works just fine casting to Gamestate however.
The very basics I am trying to accomplish is for a simple Print String. Just until I can get this call to work.
The buttons appear on screen when told to (by pressing P), then when I click on them…well, the one casting to Gamestate works, but I can’t for the life of me get ANYTHING cast to Monitor. I tried regular casting, then BPIs…nothing is getting through, I can’t even get the nodes that appear in the UMG to function right (like the Gamestate one), it’s probably something like the object (which I couldn’t figure out how to reference like gamestate), I tried making an Object Variable and putting the Monitor Blueprint in and then using that as the object…didn’t work… . Does anyone know how to make this work, so that I can cast to an Actor BP from UMG? Or is it just not possible?
A very simple way to do this is to do ‘Get All Actors of Class’, and use Monitor as the class, and then just get the index of the item you want, which I imagine is 0. This eliminates the need for casting, and works very easily if you need a quick reference to 1 specific item.
Yeah, but on the other hand, this is the worst way to do it :X “Get All Actors of Class” is very expensive.
@OP: Like you already said, you need a Reference of the one of your Monitor Actors (even if it is only one!). You could do as Jamendxman3 said, but this is not the best way.
The GameState has an overall Pointer that you can get with the “GetGameState”, so this is (like you figured out) very easy to get.
Other Actors, mostly your own ones, are harder to get. There are several ways to do this. You can create a LineTrace and use the HitActor. You can create collision boxes and
create an OverlapEvent, where you can use the “OtherActor”. If the Actor is spawned in the Level before you press play, you can also create a direct reference in the
LevelBlueprint (select the Actor and rightclick in the LevelBlueprint). OR If you spawn the actor runtime, you can directly save the spawned actor in a variable.
You need to think about how you can interact with the Actor. For example an enemy could get hit by a sword (overlap). A car can be used with E button (LineTrace on E press).
If you know what relation the two actors have while you want to interact, then you know how to get a reference of one of them.
And depending on where you create your Widget, you can then pass the reference down to it.
For example lets say your Monitor is already placed in the world. And lets say your Widget will be create when the map starts.
So you can select the Monitor, add a reference to the LevelBlueprint and pass the reference to the Widget which you also create
in the LevelBlueprint. You can create variables in the UMG Widget that you can set to “Editable and Expose on Spawn”. With that
you can fill the variable which appears in the “Create Widget” node, once you selected the Class you want to create.
I guess i could give you a more specific answer, if you tell me when, where and how do you create and spawn the widget.
And what Monitor is and when/where it is spawned.
This is the overall setup I am envisioning: I have a monitor in front of me, I call up the Camera Selection Screen (via a input key), which brings up the UMG. What I would like to do from there is the player to pick which room he wants to view on the monitor (Once he clicks on the button, the UI reverts back to normal HUD) and he sees the camera image on the Monitor. Sort of like in Five Nights at Freddy’s. I looked at Epic’s SecurityCamera/Monitor example, but that calls for an array and then it just goes in sequential order through the cameras. So, my original thought was, well, if I could just cast from my UMG button to the Actor (in this case the Monitor), I would be able to select which Security Camera to activate. I am thinking something like 20 cameras (placed before runtime) throughout the level, which I am thinking about making an Enumeration with the Roomnames now, and using an Enum switch to fire off which room the camera is in and have it display on the monitor (I’ll have to figure out how to delete the previous image/turn off the camera in memory like Epic did, but that’s another problem for later).
I wanted to ask a few questions:
First, do I really need to create a reference in Level BP, just so that I can cast to my Actor BPs from anywhere?
If not, since I am wanting to change the scene texture 2d image material on the monitor, how would I best be able to call upon that?
And his response:
My thing is, when you look at the camera/monitor blueprint that they have in their examples, they are not referencing the other Actor BP in any way (that I can see).