[solved] How can a blueprint know something happened in another blueprint? Or change a variable?

Hello,

I started using UE a few weeks ago and read a lot of tutorials, watched videos and always tempted to ask something but eventually figured it out myself. However, now I am at a point where a lot of things work but a very few are driving me nuts concerning blueprint communications. So here’s the basic game I want to create simply to gather more experience:

  • Have a car (1 for now, “car_bp”) drive forward until it arrives at a crossing point (“xing_bp”)
  • If the crossing has a red light, stop, if it turns green, continue.
  • There is more than one crossing present in the game.

Some facts:

  • the only thing you can control is changing the traffic light on each crossing by clicking with your mouse on it
  • both BPs are actor blueprints
  • the traffic light is a sub component of xing_bp.
  • inside the car_bp the ActorBeginOverlap is fired when it arrives at a crossing. There, it checks if the light is red. If yes, set moving speed to 0, else set to 2 (default speed when game starts so the actor moves at all).

All that is working except for one thing:
the car actor stops at the crossing if a red light is present and the overlap never ends.

I tried setting up a loop checking if the light has changed but that ends up in an infinite loop event. Then I tried to cast to the blueprint (inside car_bp) and read the “red?” boolean variable but I lack a wildcard object. I believe I have not fully understood the blueprint communication yet. There are lots of guides but usually they refer to “get player controller” as objects etc but the car is not the player. I generally got troubles with the cast to and finding the right object.

There needs to be a way for car_bp to know when the player clicks the current traffic light that it switches to green to resume movement. But how?

Maybe something like this?

Car → Screenshot - 849c751a652dcdb006b360cd5544ad8e - Gyazo
TraficLight → Screenshot - 0afe5df2d86a8942945f1454911f15a7 - Gyazo

Maybe something like this?

Car → Screenshot - 849c751a652dcdb006b360cd5544ad8e - Gyazo
TraficLight → Screenshot - 0afe5df2d86a8942945f1454911f15a7 - Gyazo

It seems I still got the same issue of understanding how it works to check or change variables of other blueprints.

The blueprints you posted, is the bigger one a level blueprint or a blueprint class?

Both my blueprints are actor blueprint classes so whenever I use cast to I lack a working object. When I try to connect a matching wildcard object (with context enabled) inside the xing_bp I get something like “target: self” and “target”. Yet self would refer to xing instead of car so that won’t work. I find no way to refer to the car object (or its variables) from the xing_bp and vice versa.

I am sure there is some way in UE to change or at least check variables of other blueprint classes?

If I used the level blueprint I guess I could get it working but would it make sense? To my limited understanding this should not be used as you want to write one blueprint for a class that works with all cars and crossing in my case.

One is in the traffic light actor and the other in the car actor.

I’m getting “other actor” from the begin overlap on the trafficlight casting to car and if it is a car I’m setting “my car” to whatever car just entered my collision. Then I can use that as a reference to call events from the trafficlight to “my car”

Oh wow! Now I get it! Feels like a light bulb appeared over my head. It’s working! I guess I need a better thinking and more experience in blueprints. It’s still quite something to get used to instead of writing code lines. :wink:

So here was my mistake:
I put the overlap event into the car_bp. Since I am still new to UE I did not get the idea to refer to an object and then, as you suggested, use that same one and connect it simply to other nodes which are not tied to the overlap event directly.

Now that I moved the overlap event to xing_bp I can refer to the car while overlap AND finally modify car’s speed variable during the click event.

Thanks a lot! It was vital for me to understand how this works as I am sure such things will be more frequent in future projects!