Blueprint Interaction (Booleans/Custom Events)

Hi

I’m currently working on a school assignment and have run into an issue.

In my game prototype the player will pick up certain objects, when something is picked up I want to run a custom event which will set booleans to true/false.

I’ve tried Casting but can’t seem to get it working properly. And without Casting I can’t seem to reference custom events in other blueprints.

So in short, from Blueprint A, I want to run a custom event located in Blueprint B.

I also want to be able to check true/false status of a Boolean in Blueprint B from Blueprint A and C

Please advise.

in the pickup, on overlap, you can cast the OtherActor into your custom Pawn type, then you can access its variables.

or a more versatile method, would be to make a Blueprint Interface, with functions for item collection, then make your pawn implement that interface, and have the pickup call that interface function on the OtherActor, without casting. the reason this method is better, is because you may want many different actors to be able to pick things up, and it would be innefficient to cast to many different classes that may want to pick things up.

also, you generally shouldn’t have an actor directly checking or setting the variables owned by another actor, that breaks encapsulation and can lead to debugging/security/maintenance/design problems. actors should only call functions in the other actor, and let the other actor decide whether to set or get its own variables. each actor should be the only class that edits its own variables, and other actors should have to ask this actor with a function, if they want to edit or read its variables. there are some exceptions to this, but its generally good to avoid breaking encapsulation, by using getter or setter functions.

for example, lets say you had pickup items that directly changed a boolean in your character.

if you decide that you want to redesign those booleans in your character into an integer or an Enum or an array of Names, then it would break that pickup actor. so everytime you changed the implementation of collecting items, you would need to edit the Character and the Pickup, and TreasureChests, and NPCs and any event in the game that used that item system would need to be fixed…

instead, if those pickups, treasureChests, and NPCs all called a function on the character to give an item, you could change how that function works, and it wont break all the actors that use the function.

Thanks for the answer.

I just can’t get casting to work properly as I don’t know what to connect to the ‘Object’ input.

With Blueprint Interface I’ve gotten as far as setting a boolean to true/false from different blueprints but I don’t know of a way to check if that boolean is true or false.

I had this same issue before when I had a Key Blueprint which needed to interact with a Locked Door Blueprint.
I did manage to get that working. Unfortunately I don’t remember how I did it and I no longer have that project on my computer.

connect OtherActor or HitActor with your CastToMyCharacter node.

with an overlap event or a trace function, those functions return an OtherActor or HitActor reference, and those are the objects that you plug into the cast node. in your case, with a pickup overlapping the character, the OtherActor can be cast to your custom Character type.

with a blueprint interface, you can make a function that returns a variable, and these are usually called Getters. so if you wanted to check how many flowers a character collected, you would call a function like GetFlowerAmount, which can return an integer. then in your character that implements that interface, you can set up the details for how the function works. it might return an integer called FlowerAmount, or it might do some kind of calculation, where it adds up many different types of flowers, and checks if you owe flowers to deduct those, or something… the point is, the GetFlowerAmount function can be updated with new internal logic, without breaking all the actors that use that function.

That did it, thanks for the help! Much appreciated.