Hello,
I am trying to create a simple UI menu in which I have a few buttons showing different views. I made the menu using a widget blueprint but in event graph I don’t know how to insert the camera reference. I would appreciate if anyone could help me with this.
Thanks.
Hey @badea.rc! Welcome to the forums!
You can get an array of your cameras in your scene then, after getting your player controller, you can set your set view target using the get a copy function and the array number of your desired camera:
I hope the above is the solution you are looking for!
Hello and thank you for your response. As I am new to Unreal I don’t know where to get all the things from. I made an cameras array in the variable function but I don’t know how to select the cameras- I clicked on them but nothing happens. Screenshot attached. Thanks
You are close. @Quetzalcodename was showing you the nodes, not necessarily all connected. This is what you need to do, with an explanation after
The nodes need to be executed, so on construction of the widget, get a list of all cameras and store that. When you click on your button, you can then get one of your cameras from the list (I used 4 as an example) and change the view to that.
Now getting the actors will not always store them in the same order, so you probably want to get some more detail from your camera - eg a name - and then compare you cameras name to that of the camera stored in you array. This way you can be sure that the right camera is selected
Something like this:
We loop through each element of the array and see which camera name matches the camera name that we want, when we get a match, we then send that camera to be viewed.
If you do that for each of your buttons, where you simply change the camera name, then it should work for you.
Thank you for your answer. I am trying first with on camera only and I still don’t know hot to ‘select an actor in viewport’ from variables ‘defalut value’ mode (screenshot attached)
Also, in your example from Get Display Name what function do I need to add to have the one you highlighted below?
In your example you have 3 cameras that I can see, CameraActor1, CameraActor2 & CameraActorStart. You need to assign your variable StockpileCamera to one of these. For this to work with your setup do the following:
When the widget is created (Event Construct) I first loop through ALL cameras in your scene, then I choose the camera that matches the name that I am after, in this case CameraActor2. I then assign that camera to the variable StockpileCamera. So now StockpileCamera is effectively your CameraActor2. So now whenever you use the variable StockpileCamera, you are referring to CameraActor2.
When I click the button, I now set StockpileCamera (which is CameraActor2) as the camera for that I want to view from.
If you add in the following, then it should work.
Don’t hesitate to ask any more questions.
Hi, one more question: how do I string this? where to I take the CameraActor2 from? Thanks
Hey @badea.rc!
After you access that node by pulling from the return value and entering “===” then selecting “equal exactly string”, you either manually enter the name of your desired camera, or create a variable that does the same thing. Please note, this value is case sensitive.
I hope the above is what you are looking for!
Hi! and many t
hanks for your help! I managed to make it work except the Stockpile (assigned to CameraActor2) which goes to CameraActorStart instead of CameraActor2 when pressed. I don’t understand why because in the graph looks fine…
Hey @badea.rc,
That’s great! Just to double check, there are no spelling errors? Even with zooming in the works are just too small to tell. Can you also add a print string to the end so we can double check what camera stockpile is trying to access?
Hi, I solved it! Thank you very much! It works fine now. One more thing I would like to change: When playing the scene the mouse cursor starts pointing somewhere random and it stops only when I press the left click button. How can I play the scene looking from the player start camera? Thanks
Hey @badea.rc,
That’s great! But I am not exactly sure what is happening here from your description and question. Would you mind sharing a screencap and/or video of what is happening what what you mean by “play the scene looking from the player start camera”?
If I play it in the editor it starts from here, but when I pack the project to Windows it starts something like this:
Only after I move the cursor a bit I am able to see the project.
Hey @badea.rc,
What is the default position of camera actor start? And do you have camera movement enabled or disabled by default before starting your game via the menu?