Download

Communicating between separate blueprints

Hi everyone,

I’m new to the blueprinting system and I’m running into confusion left, right and center, however I know making mistakes and experimenting is necessary! I’ve followed a few tutorials to get me going and I’m concurrently building a project pertaining to my university course, which contains an object inspection mechanic inside of the ‘FirstPersonCharacter’ blueprint, and a seperate blueprint holding a spotlight which loops visibility on a timer in the event graph…the question is, how do I get the spotlight to temporarily stay visible every time the inspection mechanic is active (the sequence of the player inspecting)?

93a2b7d3184081cba0bd30ea094e14589fb65aec.png

Here is the blueprint for the inspection

c2ba2ae0979a27cfa278f1343e6a21b79f11bb64.png

The spotlight behavior logic

You can call events, modify variables, and modify properties from the Cast To node. For example, you could drag off of the actor reference pin and you’ll notice that the options that come up pertain specifically to that casted object. To modify the visibility of an object, drag off from the Cast To node and type “set visibility”.

The problem is that I’m casting to the Spotlight_BP and my cast node requires the spotlight component reference to plug into the ‘object’ pin :confused:

2017-04-06 (1).png

If it’s a component in the actor you can drag off its reference to activate and deactivate.

Hardcoded references between isolated blueprints is almost always a bad idea.
Interfaces and event dispatchers are most of the time a better communication mechanism.

The “Object” slot needs a specific instance of your spotlight blueprint.

For example, I might have a blueprint called “car_bp”. I can put several of those "car_bp"s in my level. Without referencing which one in particular you want to cast to, the cast doesn’t know which instance it’s meant to affect.

There are several ways to get a reference to the exact object. If there’s only one “spotlight_bp” in your level you could use the “get all actors of class” node, set the class to “spotlight_bp”, then drag a “get” node from the array and plug it into the object slot.

If there are more spotlights and you only want to affect one, look up how to reference specific actors. There are a ton of ways.

tldr; a cast needs an object that exists in the game world. It will affect that object only.

There’s a video explaining blueprint communication: https://www.youtube.com/watch?v=EM_HYqQdToE

In your case you can set up an event dispatcher in your character BP and call it in your Inspection event, then assign the event dispatcher in the Spotlight BP. The only thing you need in your Spotlight BP is a reference to the sending object (your character), which is easy in case you’re controlling that character. You can Get Player Controller - Get Controlled Pawn - Cast as YourCharacterBP with a pure cast (right click the cast node and convert to pure cast).

For the logic you can create a boolean input in the event dispatcher and use that for controlling whether you’re inspecting or not. So when you first start inspecting you call the dispatcher with Inspecting = true, then when you’re done inspecting call the dispatcher with Inspecting = false, and just set up a branch in the Spotlight BP.