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
Maybe someone of yous can help me there?
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.
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 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
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?
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.
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.
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
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?
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.
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? …