How to make a boolean accessible for multiple blueprints?

Hey there,
for a little game project im having a bunch of weapons which i can pick up and run around with (and fight but thats coming later).
So my problem now: I need a bool variable which indicates if im holding a weapon right now or not so i can check if i can pick up one or if i have to drop the one in my hand first. (pick up and drop is on the same button)
So how can i make a boolean variable accessible for both of the weapons?
I tried it with public variables and interfaces but nothing worked :confused:
Maybe someone of yous can help me there? :slight_smile:

so this is the setup of my blueprint of the weapon. the “holdingItem” bool is the one i want to have accessible for all other weapon blueprints.

Maybe I’m misunderstanding, but perhaps a better way would be to store the boolean variable on your character, and make it so the character itself will or won’t pick up a weapon.

But to answer your question… If you want to access variables in other blueprints, you just need to cast to them.

No youre not misunderstanding :slight_smile:

That was actually my intention to put that variable to the character and set or get it in the weapon blue prints. But im not sure how to exactly do the cast thing, do i have to initialize a new variable of the thirdpersoncharacter in each weapon? (its all based on the demo)

maybe you could show me how such a cast would look like?

Why do you want to get it on the weapon? It would be much simpler to simply have the character itself pickup/drop weapon based on the boolean.

But, if you really want to do it on the weapon while having the bool on the character, you’ll need to cast to the character. To do this, simply get a reference to the character and use that to cast directly to it and grab the bool variable.

I actually tried it a few times to attach all this pick up thing to the character but it never worked properly :confused: thats why i moved all that to the weapon. But yeah sure i can try to attach it to the character script.
So Its intended to have a sphere around the player, and if there is a weapon inside this sphere, then i can press a button to pick it up and it gets attached to the hand socket.

how can i access all the different weapon types and get them to attach to that socket? Maybe im just blind or dumb right now but i cannot get it to work :confused:

Just to be sure I know what you’re trying to do… Is it something like this?

Made that real quick, and everything is done on the player

yeah thats what i want, the only difference is that i can pick the weapon/item up when im in range of it and when i press a button but i think thats not the biggest deal… how did you implement that with those blueprints in the player one?

Oh, well I guess it isn’t obvious, but in order to pick up the weapon I have to press a key, and be in range.

Here’s how my setup works: If you’re in range of a weapon and press the key and…

  • No weapon equipped: It’ll just pickup the weapon
  • Weapon equipped: It’ll swap weapons

And, if you’re not in range of a new pickup, it’ll just drop the weapon you already have.

Here’s the BP:

It’s not perfect, but again, it’s just something I made real quick to have a visual aid. You can tweak it to work however you want

oh well this looks like what i need :slight_smile:
just a few questions for clarification:

you attached a sphere collider to the character, right?

How do i get to the weapon collision exactly?

And how did you get the 2 different weapons into one weapon class? Im just having 2 .fbx and they are from the static mesh class…

thank you so far!
just one thing doesnt want to work:

It wont accept the weapon collision. how did you setup the bp in this case and which type is the variable there?

Oh well im pretty new to all this unreal engine blueprint stuff… so im trying to learn new stuff, and it seems parent/child bps are pretty important

  1. Yep
  2. The weapon BP is simply set to collide with my character collision that I added. The character checks if anything he is colliding with has the “pickup” tag and acts accordingly.
  3. Parent BP. Create a Parent BP with any attributes you’d like, and then you can create an infinite amount of Child BPs that inherent base values from the Parent.

I suppose you could also just have simple static meshes. As long as they are tagged the character can interact with them, I think. But really, learning about Parent/Child BPs is HUGE, so I’d go that route.

What do you mean? You’re not getting any overlapping actor? Check the weapon collision settings.

You don’t need to access or interact with the weapon at all. Everything is done in the player :slight_smile:

No i think my main problem is that i cannot access the weaponcollision… how can i instantiate that variable to work, cause with a reference to the weapon class it doesnt work (obviously)…
sorry if im bothering and being blind :confused:

well… i mean the target for the “getoverlappingactors” which you called weaponcollision… i dont get how i have to set this one up :confused:

oh my god youre an angel :slight_smile:
it works finally!

there is just one little thing im worrying about:
it tells me this Error: “Error Accessed None ‘equippedWeapon’ from node DetachActorFromActor in graph ‘EventGraph’ in blueprint ThirdPersonCharacter”

do you know a quick solution for that? do i have to initialize the “equippedWeapon” in any way to avoid that error?

Ohhh

That’s the collision box on the player. You get the overlapping actors from the player Collision box, and check to see if any of those actors has the correct tag,

It’s strange you’re getting that. Is your BP the same as mine? You should never be getting to the point where you try to access the equippedWeapon variable if you’re not overlapping with a weapon.

Not a big deal. You can just check to see if it’s valid to get rid of that error.

Yep! That’s right.

And like I said before, there might be other problems since this was made real quick. But those can be ironed out when you start tweaking it

ah well i fixed it… i actually had to set equippedweapon as an actor type and not as a weapon type (i think thats correct though)

but when i picked up the weapon its pushing me to left side (im holding it in the right hand) and it seems to be a collision issue… maybe thats caused of the actor thing that i changed? …