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 I get a variable from a different Blueprint?

I'm new to Unreal and making a test game just to get the hang of things. Basically, the game starts with the player listening to a AI character making a speech. At the end of the speech, the player has to decide whether or not to flip a switch. If they decide to flip the switch (by pressing the designated button), there is an animation that the switch plays that shows it moving from one side to another.

I need to make it so that pressing the button before the AI character is done with his speech does nothing. Then, once the AI character is done, pressing the button should make the switch animation run.

I've tried going about this in every way that I can imagine. From what I've been able to gather through my exhaustive search, the best way to share variables between blueprints is using casting. Thus, the best way that I could come up with is for the AI character's final blueprint node to be a simple boolean variable "TimeToEnableSwitch." This would indicate that his speech is done. Then, in the player controller blueprint, I'd have the button-pressing event connected to a "Cast to AI Character" which would then allow me to "Get TimeToEnableSwitch." Finally, I'd connect that to a Branch --> if it were true, then the switch should play the animation, otherwise do nothing.

The problem is that I don't know what I'm supposed to connect to the "Object" input node in "Cast to AI Character," and when I try to compile I get errors saying "The type of object is undetermined" and "The current value of the object pin is invalid."

Can anyone help me find the right node to plug into the "Object" input?

Product Version: UE 4.15
more ▼

asked Jul 13 '17 at 04:52 PM in Blueprint Scripting

avatar image

1 1 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

For the future I recommend watching this video, which is the bare minimum you have to know about Blueprint Communication and Casting. The object pin is a reference to the AI Character and by casting you basically get access to all the functions in your AI Character. This reference of your AI Character is usually saved when you Spawn the AI or if it's already in the world by dragging it into the level, you can make a reference in your Level BP. If you didn't understand what I said, please make sure to watch the video as it will give you a solid understanding of casting. <3

more ▼

answered Jul 13 '17 at 05:09 PM

avatar image

4.2k 88 38 152

avatar image rileykermanian Jul 13 '17 at 06:14 PM

Thank you, I really appreciate your help. However, this specific instance seems like something that should be pretty simple to implement. I know that I should watch the video to gain the bare minimum knowledge that I will definitely need for the future, but I was really hoping you could pass along the quick fix just so I can get this to work for the time being. Please and thanks!

avatar image Ninjin Jul 13 '17 at 06:17 PM

But I did give an answer, you need a reference of the AI Character that you get when spawning the AI or from the Level, or did I miss something?

avatar image rileykermanian Jul 13 '17 at 06:26 PM

Thanks for your help. I don't know exactly what you mean by "reference." I've tried connecting "Get Owner" to the "Object" node (that's what intuitively makes sense to me) but it's not working. Where do I find this reference? And when I drag off a pin from the "Object" node, what should I type in order to select that reference?

avatar image Nachtmahr Jul 15 '17 at 08:07 PM

What Ninjin means by refference is a individual instance. You can have 100 Ai Characters in the Scene and a refference points to exactly 1 of them. In your Case the AI you currently Speak to. But the refference has to come from somewhere. Overlaps return you a Actor for Example and you use that Actor as Input for a Cast Node to find out if the Overlapping Actor is a AICharacter type or something else.

We dont know your Setup so we cant give you a direct Answer. But the Video covers most essentials. If you Spawn your AI dynamicly, the one who Spawned it has the refference and can Send it to others he has or can get a refference to. If you simply placed your AI In the Level than you can select it->Open Level BP->Rightclick and add refference (No Cast needed btw its already the right type). You Level only knows about things you Placed before you start the Game so be aware of that.

Thats what a refference is. A Pointer to a Specific Object that exists. Without it you cant Communicate to that Object.

(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