Retrive a variable value from a random blueprint

Hey guys,

I’m trying to build a small game where you can grab objects and build structures with them. Each object has a boolean variable named “inAStructure” that reflects it’s current status… if it’s already in a structure or it’s just laying on the ground.

Right now I can know the value of “inAStructure” by manually asking that blueprint (see attachment). But what I want to achive is:

  • if trace hits any blueprint with tag
  • return the value of “inAStructure” if any.

Thanks!

I don’t see any added attachment if you meant to include one.

The documentation on using Raycasts in UE4 is pretty complete. In short, the first thing you want to do is try and get your blueprint into a debugable state, you can view the trace that is being emitted from your character for example, and then have returned what it is that it collided with.

I would have a look at the following documentation and make modifications accordingly to fit what you need.

Hope this helps!

===============
adding from my comment

If you want to be able to cast to a blueprint, which I think is what your problem is, you need to make sure that you have a base class blueprint with the variable you want and you need to make it inheritable (the variable).

In code what I would do is make a base case with the boolean variable and expose it to blueprints, and I would make it virtual, this base case can be just a generic class you could call it BaseStructure, from there every other class would needs to inherit from that base class, or from a class that eventually inherits from BaseStructure.

CastTo works the same way as casting works in vanilla C++. Is this game pure blueprints or are you playing in C++ also?

https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseRaycasts/Blueprints/index.html

my problem is: I don’t know what I will hit. It may be a wall blueprint, a pillar blueprint, a window blueprint… but all of them have a bool with exactly the same name.

In my attachment I get the bool variable from a blueprint manually picked from a dropdown called “StructureCorner” but I want to Cast To anyblueprint that was hit by my trace and get the value of variable called “inAStructure” if it has one.

Thanks!

I guess I found my answer:

“The use of Blueprint Interfaces allows for a common method of interacting with multiple different types of objects that all share some specific functionality. This means you can have completely different types of objects, such as a car and a tree, that share one specific thing, like they can both be shot by weapon fire and take damage.”