Get variables drom a blueprint to an other

Hello everyone,

I’m pretty new to Unreal and especially to visual scripting so i’ve followed a tuto on youtube to make a hover. The vehicule works fine but i have problems when I try to climb obstacles. I’m trying to fix that by setting a variable to 0, but problem I need a variable from a second blueprint and apparently we can’t just get it and work with. I’ve tried with CastTo, GetAllActors and even create a variable wich is directly the other blueprint but nothing work, can someone help me please ? I’ve seen an other post talking about the same problem but there is no good answer.
Or maybe have you a solution to stop my mesh rotating from an angle to an other ?

Give an example of how you try to use GetAllActors combined with CastTo. It should work.

So your touche pas variable is on your hover component, and your hover vehicle wants to access it?
Is the hover component part of your hover vehicle?

You need to set a target to the “target” input on the “get touche pas”-node that you have on your hover blueprint. The target needs to be your hover component. Otherwise Unreal Engine will not know where to find the variable, unless “hover vehicle” *also *has a “touche pas” variable. Then it will just take *that *one instead of the one on your hover component, because you told it to use the “touche pas” from “target self”.

You also said that you tried to make a variable of type “hover component”. But did you actually give the variable any value?
A variable of a class type will not contain an item of that class. It will contain a *reference *to an item of that class. It’s not enough to tell your friend to go to a house - you need to tell him the address of the house.
The tricky part is to find a good moment to give your variable the correct reference.

If the hover component is already a child of hover vehicle, you can just tell it to “get parent”, then set the “hover component reference” variable on the parent to “self”. (Because “self” in this case would be the hover component)
But that’s probably unnecessary.

There is a variety of ways of accessing your variable, depending on what you did:

The easiest way, if you already have the component attached to your vehicle in the editor, instead of during gameplay, is to just drag it from the list of components into your blueprint. This gives you the reference.

Afterwards just drag from the reference and type the name of the variable that you want.

If you added the component during gameplay, you need to have a reference variable. So when you add the component from the hover vehicle’s blueprint:

You can just drag from the “add” node to take the reference and input it into the reference variables.

I created two reference variables, to show you casting:
Screenshot (125).png

“Test reference” is of type “test”, so I can just drag from it and get to the TestVariable.
“Test reference general” is of type “actor component”. Test is an actor component, so it can be saved as an actor component variable, but a camera or a gun is also an actor component. Unreal Engine does not know what you saved inside of this, it only knows that it’s an actor component.

So if you want to get a variable that only “test” has, you need to use the “cast to” node. When you cast to type test, the engine checks if “test reference general” contains a reference to an object of type test. If the variable is of that type, the cast will work. If it isn’t, “success” will be false and you cannot access the variable.
So if you accidentally save a reference to a camera in your “Test Reference General” and try to get the variable “TestVariable” from the camera, even though cameras do not have a variable “TestVariable”, the game will not crash. It will just skip that instruction.

It will also prevent you from getting the variable “TestVariable” from something that has the variable “TestVariable”, but is not of class “test”. (For example, imagine getting the “identification” variable from a house, which will be its house number. But you accidentally try to get “identification” from a car instead, which is a license plate. If you cast to house, you won’t accidentally load a license plate)

Thanks both of you for your answer.

vb4, so here is how I’ve setup the thing :

I’ve attached a print string to the “touche pas” variable to see when it is affected and my “vitesse” float still doesn’t change.

Here is the Hover_Vehicule blueprint setup :

491c772849279bbbe8965e53c27dd645275dd30d.jpeg

If I understand correctly (what I doubt) the CastTo node is use to go search in the HoverComponent the “touche pas” variable ?

Sorry, I assumed that you were a bit more experienced than a complete beginner. I hope I didn’t confuse you too much.

First of all, you don’t need to do “add hover component”, because your hover vehicle already has four hover components.
(Why do you have four?)

You also don’t have to name the variable “Test Reference General”. Any name works.

In your case, you just need to drag your hover component into your blueprint, like I showed in the second image with the arrow. Put it where you have “Test Reference General” and “Cast to hover component” right now.

Also, if you want to use a node like “add hover component”, you need to make it activate somehow.
Your “Event Tick” is an event. Events create execution pulses. The white wire that is coming out of the event carries the execution pulse.
If you don’t have a white wire that is going into your “add hover component” node, it can’t get an execution pulse. This means it will never do anything.
Event Tick fires a pulse once a tick (the internal time unit of the engine), Event BeginPlay fires its pulse once when the blueprint enters the game. You can even make your own events, but that’s for when you are more advanced.

As for the CastTo node, it’s best to use an analogy:
Imagine a plot of land. On that plot of land might be a house.
If there is a house on the plot of land, you want to read the house number of the house. If there isn’t a house, you don’t want to do that.
That’s when you use a cast. If your engine already knows that there is a house, you don’t have to cast.
In your case, this means that you only need to use CastTo on the “Test Reference General” variable if “Test Reference General” is not of type “Hover component”.

Anyway, forget CastTo for now. You can do this without it. I just wanted to show you a few possibilities.

I hope this has been a bit clearer for you.

Sorry I was’nt at home.

The HoverComponent you see in the list (1-2-3-4) are not the same as HoverComponent I want to access. They are just squares with force on them. i want to get a variable of the HoverComponent blueprint which is totaly different of these actors.
I’ve renamed the assets for help you understanding what I want :slight_smile:

So this is the Hover_Pawn (previously the Hover_Vehicule) which is in the game :

Each Force corresponds to a thruster (there are 4 of them).

In this blueprint I want to get a variable from the Hover_SceneComponent (previously HoverComponent) to reduce the “vitesse” variable (contained in the Hover_Pawn blueprint) when the boolean is true.

But here is the problem, I don’t know how to get it to work. So which one of your solutions should I use ?

I come from Unity and this blueprint system is really difficult to understand at least for me.

Maybe just my personal preferences, but if i create a variable that i don’t plan to use locally (i.e. i wanna read it from other blueprints, too) the first thing i make is 2 functions - one to GET it and one to SET it. Something like “GetHoverTouchePas” or whatever, just add a return node and prolly also make it “pure”.

I’m sure it’s the best way to do but is there a more simple method ? I’m not really in search of purity ^^

This is funny, because I recently tried out Unity and had no idea how to get references to other objects.

So, your Hover_Scene Component is something that exists inside of your game world? (Just making sure - If it isn’t, you need to put it there in some fashion)
Am I right in assuming that the component only contains data but isn’t something visible in the game world?

And your Hover_Pawn is your player pawn, right?
If yes, you can just call “get player pawn” in your Hover_SceneComponent, cast it to Hover_Pawn and then either give the Hover_Pawn a reference to Hover_SceneComponent or make Hover_Scene_Component do the change of the Vitesse variable.
In that case, you could give your Hover_Pawn a function, which takes a boolean as an input. Hover_SceneComponent gets player pawn, casts it to Hover_Pawn and then calls the function and uses touche pas as the boolean input.

Basically, your Hover_SceneComponent would be the one to activate the change of the Vitesse variable.
If you need Hover_Pawn to do it, you can instead give Hover_Pawn a variable that would reference the Hover_SceneComponent, then tell Hover_SceneComponent to access Hover_Pawn like I just explained, and tell it to set the variable to “self”.

I hope it’s not confusing. I couldn’t do screenshots for the explanation today.

Un Unity I don’t need that much help to get what I want, C# or JS ^^ but in ue4 wow I feel like a no brain man…

I will try tomorrow and say if it works :slight_smile: thanks for helping me

It’s too difficult for me. I’m a total noob and it burns my nerves.
No matter, thank you so much for your help. I think I will go on a “graphisms project” but optimization is bad, event with only two trees with 5 LODs.
Thanks again vb4 :slight_smile: