Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to Switch between two Blueprint classes using widget buttons

I wish to create a widget where once u click a button u can shift between one blueprint class(containing a camera with a spring arm attached) to another blueprint class. I have seen some post but they have assigned a keyboard shortcuts ( 1 and 2) for doing the same.

Product Version: UE 4.10
more ▼

asked Jan 05 '16 at 11:19 AM in Blueprint Scripting

avatar image

Suraj Nair
1 2 5 4

avatar image Matthew J Jan 05 '16 at 08:50 PM

Hello Suraj Nair,

When you say "switch" do you mean that you're switching what you are possessing? Do both of these blueprint classes have instances already spawned in the level at the time of this switch? What types of blueprints are these two classes, as in Character, Pawn, or Actor?

avatar image Suraj Nair Jan 06 '16 at 04:30 AM

Hi Matthew Clark,

Thank you for replying, what I meant by 'switch' was to posses from one class to another class which are both pawns.By instances do you mean both the pawns are in the view port..? if so then yes.

Below is what my view port looks like alt text

both the cameras are pawns with just spring-arms attached to them

viewport.jpg (48.4 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Thank you for clarifying that. Here's a simple way to do this with your current set up.

This method is assuming that both pawns are of the same blueprint. If they're not, it should be even easier as you can set the references before runtime.

In the pawn's blueprint, make a variable that stores a reference to this type of blueprint, so if you're working in the ThirdPersonCharacter from the template, you'd be setting up a variable that is a ThirdPersonCharacter actor reference. After that, set up the following nodes (OtherReference is my variable).

alt text

This allows us to look through all of the instances of this type and get a reference to the other one in the scene.

After that, create the widget blueprint for your button. Add a button and then in the details for the button, click the + beside "OnClicked".

In the event graph that appears, you can add the following nodes.

alt text

This gets the currently controlled pawn, makes sure it's of that blueprint class, and then gets its reference variable to tell the player controller what to possess.

Let me know if you run into any issues. Hope this helps!

more ▼

answered Jan 06 '16 at 03:08 PM

avatar image Suraj Nair Jan 07 '16 at 11:34 AM

Hi Matthew,

I did what u said and it works but am having issues when the game starts.

1.When I click play the camera shifts to a position which I have not placed

  1. I have two cameras named Cam_01 and Cam_02 (pawns) placed in the view port but the switch happens only with 1 camera and the other cam mentioned above. I may have messed up something

alt text

I created a switch based on what you have said and it works but not between the cams I want

alt text

viewport.jpg (61.2 kB)
switch.jpg (92.7 kB)
avatar image Matthew J Jan 07 '16 at 02:50 PM

Could you show me the logic you added to the blueprint for these two pawns as well? When using two different blueprint classes, you shouldn't need anything as complicated as that for the button's logic. You can do this:

alt text

avatar image Suraj Nair Jan 08 '16 at 06:12 AM

Hi Mathew,

thanks for that. I have fixed it but there is one initial problem about the camera switching as above the positions of my cam in the view port are different than what they show during Game Play

avatar image Suraj Nair Jan 08 '16 at 06:20 AM

this is the Cam_01 blueprint.

alt text

I don't know if adding just a capsule collision is a mistake but i was trying to achieve it like the third person camera


alt text

and this is the result I am getting currently

unknown camera

alt text


alt text

cam_01.jpg (188.4 kB)
camera 2.jpg (177.6 kB)
cam with issue.jpg (52.8 kB)
proper camera.jpg (56.4 kB)
avatar image Suraj Nair Jan 08 '16 at 06:22 AM

thank you for helping me out on this

avatar image Matthew J Jan 08 '16 at 01:40 PM

Are the cameras placed into the level before runtime (before pressing play)? If so, you may want to check the World Outliner to see if you're ending up with 3 cameras. It may be spawning a 3rd one to possess rather than attempting to possess one of the ones already in the scene. If that is the case, you should be able to fix this by selecting one of the instances of the pawns in your level and changing the "Auto Possess Player" in the Details panel to Player 0.

avatar image Suraj Nair Jan 11 '16 at 07:08 AM

there is no third camera in the scene. This is how the outliner looks like

alt text

what is the type of variable You had used for referencing the "Third Character blueprint" here

alt text

cause if its a pawn type of variable then it does not connect to Array element(For Each Loop), but in the event graph of my widget blueprint it gets connected to the posses function only if its a pawn type variable

Cam_01 alt text

Mouse_interface alt text

unreal prob 1.jpg (26.3 kB)
unreal 2.jpg (47.0 kB)
unreal_3.jpg (44.9 kB)
unreal_4.jpg (97.3 kB)
avatar image Suraj Nair Jan 11 '16 at 07:16 AM

the last time I connected it was by first changing it to an Actor type variable so it connects with the Array element and later change the variable type again to Pawn so that it gets connected to the Posses Function.

avatar image Matthew J Jan 11 '16 at 02:18 PM

My particular one was "ThirdPersonCharacter" but the reference variable should be set to a reference to your particular class, so it should be a "Cam_01" or "Cam_02" reference, whichever one it is trying to point to.

avatar image Suraj Nair Jan 12 '16 at 07:12 AM

Hi Matthew, what I was asking was when you create a new variable it is originally a boolean type by default, so what type of variable did you place as a 'set variable' for referencing the pawn.Is it a pawn type of variable or an actor type

alt text

vari type.jpg (168.4 kB)
avatar image Matthew J Jan 12 '16 at 02:09 PM

Yes, that is what I mean. In the field at the top of that, type in Cam_01 or Cam_02, depending on which one you need. It'll give you a Cam_01 or Cam_02 reference and give you an option of 4 different types. You want the object (blue) reference.

avatar image Suraj Nair Jan 13 '16 at 06:13 AM

Thanks Matthew they are finally connecting I didn't know they would appear there :)

the switch is working finally but still stuck with a third cam. The switch is happening between cam_01 and the 'Player start'. I tried first selecting one of the pawns and changing the 'Auto Posses Player' to 'Player 0' But then the switch does not happen

avatar image Matthew J Jan 13 '16 at 01:32 PM

This may be related to how your Gamemode is set up. It should be able to be set to None for the Default Pawn Class seeing as you're going to be possessing something that already exists in the scene when the game starts.

avatar image Suraj Nair Jan 14 '16 at 06:49 AM

Hi Matthew, I restarted everything and did what you said but now the cam goes somewhere else and does not switch is it possible if I can send you the file so that you can have a look at it..?

avatar image Matthew J Jan 14 '16 at 01:23 PM

Of course, you can send a link to a download for the project either here or to me directly in a private message on our forums. Here is a link to my profile.

avatar image Matthew J Jan 18 '16 at 03:02 PM

Hello Suraj Nair,

There was a problem with the project that you sent me. Could you please check your private messages on our forums for the details?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question