Share Common Variable between Mutliple Blueprints?

Hey there,

I have a quick question about sharing variables between blueprints.

I am creating a procedural path, after the player travels a certain distance, a new path piece is spawned in front, and one is removed from behind.

The path is made up of 12 individual blueprints, each one has a “Spline” variable, now because these are all spawned randomly, I’m wondering if there is some way to get that variable that is common to all of the blueprints.

Maybe something like casting to a TYPE of Blueprint? I know I could just do 12 cast nodes, but I’m sure there has to be a better way to do it.

Does that make sense? Any help would be much appreciated!

Spawning the path from an array of classes

I notice that you’ve entered this same issue 3 times …

Use class inherence, Blueprint are same valid classes as C++ classes and they can inherent parent variables, this way you can cast to parent class to access variable (or event) of multiple subclasses. Here tutorial about objects and classes in UE4, they will definitely show you the way:

Wow what the, did I? I’ll get rid of the other ones.

I already closed them :stuck_out_tongue:

Cheers for the help! I started looking into parent classes like you suggested, will this allow me to have a different spline for each child?

I can see the inherited components, but can’t seem to modify them or set them. If I cast to the parent, am I supposed to be able to see the variables of the children?

Thanks!

No, child will have variable of parent, you can cast to parent to access it regardless what child class you operate, you can place anything in that varable. So make parent without spine component, make it on child and reference it in single varable. Btw you could also search for spline component from component list too without need of varable

Alright I see where that might be useful, it seems like I can only see components inherited from the parent, not variables. Is that correct?

I am slowly getting my head around it haha, hopefully this clears up what I’m trying to do a little bit:

][1]

(So there are 12 different versions of this blueprint, and I’m trying to pull the spline out of each one so I can align my character to it)

Trying to avoid having to do this, haha.

Child inherent everything (Except anything marked private, check if your variable is public), components, variables, functions, events even stuff from C++ classes which might be invisible in blueprints.

Theres should be checkbox which allows you to see inherited variables, if not you can always access all variables via context menu, when you drop object link.

You could set them up in an Array or with Get All Actors of Class which returns you an array. Then use a ForEachLoop, it will fire as many times as there are elements inside the array.

I know that this is not how you are going to end up setting up your functionality but for future reference you can right click on those casts and convert them to pure casts.