x

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"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

How can I use a variable from another BP?

In animBP, I want to use a variable from character BP. i.e.) When I click the screen, a variable is set. If the variable is 1, an animation will be started.

Product Version: Not Selected
Tags:
more ▼

asked Nov 03 '16 at 03:35 AM in Blueprint Scripting

avatar image

angnim23
5 1 2 4

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

Great question! The process is actually pretty simple...

1. The first thing you will need to do is set the variables to public so that they can be accessed by other blueprints. You can do this by clicking the "eye" at the right end of a variable.

Player Blueprint

alt text

2. Next, you will need to create a reference to your character inside of the Event Graph (Get Player Character -> Cast to "your character here" -> promote to variable -> "Player".

3. You now have access to all of the player's public variables via the "Player" variable.

Animation Blueprint

alt text

Let me know if anything still needs clarifying and I'll be happy to help.

step one.png (344.5 kB)
step two.png (508.4 kB)
more ▼

answered Nov 03 '16 at 08:39 AM

avatar image

KenBrace
31 3 9 10

avatar image angnim23 Nov 03 '16 at 08:59 AM

Thanks to your answer. I made the variable public, and I followed every steps. But animation is not working.

qq.png (153.5 kB)
avatar image KenBrace Nov 03 '16 at 09:16 AM

You need to create a variable inside of the AnimBP and then use your player reference to set that variable. You can then use the var owned by the AnimBP to control state transitions.

alt text

animbp.png (113.7 kB)
avatar image KenBrace Nov 03 '16 at 09:20 AM

Here is a shot that includes the variable created inside of the AnimBP...

alt text

animbp2.png (84.5 kB)
avatar image angnim23 Nov 03 '16 at 10:01 AM

Oh, I succeeded. I just omit a link.. sorry. hahaha. anyway, thanks your answer again.

widget 1.png (38.0 kB)
widget 2.png (150.2 kB)
avatar image KenBrace Nov 03 '16 at 10:18 AM

Awesome! If it's not too much trouble then marking this as the answer would really help me out. Thanks and good luck with your project! :)

avatar image angnim23 Nov 03 '16 at 10:39 AM

I did :)

If you answered my last question, I would be really happy. As far as I know, I should " get user widget " to object, but I can't find the node even by searching.

avatar image KenBrace Nov 03 '16 at 11:09 AM

No problem at all. Accessing a widget's variables is even easier. Just create a variable and set the type equal to a reference of the widget.

alt text

Then use the widget reference variable to access vars and set them inside of the AnimBP...

alt text

widget 1.png (38.0 kB)
widget 2.png (150.2 kB)
(comments are locked)
10|2000 characters needed characters left

Just make sure to make them public before you could use them in over blueprints. Also make sure that you have the correct instance of the blueprint for you to get references or attributes from that blueprint.

more ▼

answered Nov 03 '16 at 07:32 AM

avatar image

AlsonEntuna
81 2 5 8

(comments are locked)
10|2000 characters needed characters left

The way to go about this is to just use a single cast to your CharacterBP in your animationBP.

alt text Here I just wanted to show all the variables I have in my FirstPersonCharacterBP that I can call later in the animationBP.

alt text Use a simple cast to access all of the variables you created, in your case either a float or int variable to check when it is equal to 1. The object of this cast here is 'TrytogetpawnOwner' which is usually your playercharacter.

alt text

I don't know if you are familiar with state machines but you can set the whatever condition you want in order for you character to transition into the animation you want. In my case here my when I hold down a button, it sets the 'Firing?' boolean variable to true which allow my character to enter the shooting animation.

Hope I answered what you are looking for. Hope this helps.

variables.png (727.9 kB)
animbp.png (823.9 kB)
more ▼

answered Nov 03 '16 at 07:20 AM

avatar image

Nken418
353 11 3 14

avatar image angnim23 Nov 03 '16 at 07:56 AM

First, really thank you. I'm a noob, but I can slighly understand a cast node thanks to your help.

btw, I tried disconnect original white link and connect to "cast to firstpersoncharacter" just to test. Print is shown, but the animation is not started. What' wrong?..

following image is character BP, widget BP(HUD), anim BP

alt text

q.png (136.8 kB)
avatar image Nken418 Nov 03 '16 at 08:35 AM

I'm sorry it's a little difficult to understand what you are describing here, but I assume you are referring to the white exec pin. Can't you just continue the chain? Anyways here is the same animationbp zoomed out so you can see what I connected to what.

alt text

From what I understand, TryToGetPawnOwner is used for animation blueprints. In your hud you can just PLayerCharacter as the object in your casting for your character.

image1.png (421.5 kB)
avatar image angnim23 Nov 03 '16 at 09:06 AM

In widget BP (HUD) case, when a button is onclicked, a variable is set. In anim BP, getplayercharacter is not matched, printing warning.

alt text

hud.png (62.4 kB)
(comments are locked)
10|2000 characters needed characters left
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