Basic referencing of a variable in 2nd Blueprint

So after all the tutorials and videos I’ve researched regarding communication between blueprints, I seem to be missing some very fundamental basics. I’m really feeling like an imbecile for not being able to grasp this…

Intention: Have one blueprint define a variable (a random integer in this case), and a 2nd blueprint that prints that integer to the screen.

31653-blueprintb.jpg

I’m not sure what I am supposed to set that target to that is throwing the “This blueprint (self) is not a BlueprintA_C, therefore ‘Target’ must have a connection.” error.

Could someone help me out?

You have to use a cast.

You need to get a node that can target where the blueprint is you are trying to get information from, then cast from it to get your item.

In this case, my screen width variable is in my fps_controller, which relates to my player pawn. So I get the player pawn, then cast to the blueprint with my info i want, and get it.

You aren’t limited to just Player Pawn to cast, this is just an example.

I’ve tinkered with casting, but I can’t seem to get it working.

The only things I have created and named in this scene are:

  1. BlueprintA
  2. BlueprintB
  3. PrintMe (Random Int Variable)

I can’t seem to name or pin any of these 3 things to the casting node, and thus can not get this network to complete successfully. In your example you use a “get player pawn” function, but I’m not sure what the analogous node would be in my scene.

Could someone please explain to me the relationship between the cast node and the object it references?

You need a reference to the object you are trying to cast. How you get that reference depends on things like how you are spawning the blueprint in the level, what type of blueprint it is, etc. The way maverinox showed you is how to get a reference to the player pawn, the engine has a built in node for it. If the blueprint you are trying to cast to isnt a pawn that node wont work for you as you have found. If you didnt make a reference variable when you spawned the blueprint you can use the “Get all actors of class” node, make sure to set “Actor Class” to the blueprint you are trying to cast to. Then pull a get node from that and set it to 0 (if you only have the one blueprint it will be 0 in the array) and pull from that get node to your cast to node. The better way would be to make a variable for the object and set it when you spawn the blueprint that way you can just check if the variable is valid and if it is cast it. Hope that helps.

Gilabite…

I LOVE YOU.

You are like my favorite person in the world right now. I’ve been asking this question for like 2 weeks, and no one has been able to tell me the words “Get all actors of class, etc”. I would kiss you right now.

lol no problem glad I could help. Just be aware that that method may have some limitations depending on what you are doing, but I assume you are just throwing some things together to learn. Look into the last part of my comment, you will want to learn how to do that as well :wink:

To cast, you need a reference. In my case, I used the Player Pawn because the FPS_Controller blueprint relates to the Player Pawn. So, to cast, you do the same thing, but instead of Player Pawn, you would get a variable that relates to it (basically a child of it.) You would need a variable storing the BlueprintA reference.

If you don’t have a reference variable, you can’t cast.
To try and get the idea, take your BlueprintA, and drag it into the scene. While that actor is selected, go into your Level Blueprint, right click, and there should be something like “Create a reference to BlueprintA.” Click it and it should create a reference variable to that specific actor in the scene. Drag off of it and try casting to BlueprintA.

Casting can give more control to access specific actors and the like. For instance, what if you had 10 BlueprintA’s and only wanted to access one?
There’s almost never one way to solve a problem in programming, however, if you still wanted to cast, you would need a reference to that one object.

Can u explain this in understandable words ?
Or even better an example with the Blueprints so we noobs can see what u are talking about, which sounds like a lot of mysteries that get solved by secrets hidden far away beyond the hoizon of my basis-basic Engine understanding.

Well, using blueprint interfaces is a tad easier. Search the Unreal Engine channel on youtube for blueprint interface tutorials. They are pretty easy to follow.

Thx for the tip, Alper.

Sadly, the Interface Videos in the Unreal Engine Channel are outdated, if I trust the comments on them. Same goes for the Unreal Engine Documentation, it is outdated and new users will have a hard way to find out, which way they can do things, and which way not.

I don’t get how they are outdated. I currently use 4.7 build and still create interfaces the same way.