x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 :/ Maybe someone of yous can help me there? :)

alt text

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.

Product Version: UE 4.10
Tags:
naginata.jpg (315.2 kB)
more ▼

asked Dec 10 '15 at 01:18 AM in Blueprint Scripting

avatar image

Maraeil
13 1 4 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Dec 10 '15 at 02:41 AM

avatar image

vanlacke
1.5k 65 132 103

avatar image Maraeil Dec 10 '15 at 09:55 AM

No youre not misunderstanding :)

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?

avatar image vanlacke Dec 10 '15 at 07:36 PM

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.

avatar image Maraeil Dec 10 '15 at 08:40 PM

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 :/

avatar image vanlacke Dec 10 '15 at 09:36 PM

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

https://www.youtube.com/watch?v=Frvdt76WU4s&feature=youtu.be

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

avatar image Maraeil Dec 10 '15 at 09:45 PM

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?

avatar image vanlacke Dec 10 '15 at 09:53 PM

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:

alt text

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

pikcupbp.png (225.2 kB)
avatar image Maraeil Dec 10 '15 at 10:17 PM

oh well this looks like what i need :) 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...

avatar image vanlacke Dec 10 '15 at 10:23 PM
  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.

avatar image Maraeil Dec 10 '15 at 10:34 PM

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

avatar image vanlacke Dec 10 '15 at 10:52 PM

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

avatar image Maraeil Dec 10 '15 at 10:55 PM

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 :/

avatar image vanlacke Dec 10 '15 at 10:58 PM

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

avatar image Maraeil Dec 10 '15 at 11:01 PM

well.. i mean the target for the "getoverlappingactors" which you called weaponcollision.. i dont get how i have to set this one up :/

avatar image vanlacke Dec 10 '15 at 11:13 PM

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,

avatar image Maraeil Dec 10 '15 at 11:22 PM

oh my god youre an angel :) 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?

avatar image vanlacke Dec 10 '15 at 11:29 PM

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.

avatar image Maraeil Dec 10 '15 at 11:39 PM

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? ..

avatar image vanlacke Dec 10 '15 at 11:40 PM

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

avatar image Maraeil Dec 10 '15 at 11:44 PM

Yeah i got it ^-^

ah well thats something for tomorrow to work on ;) now i can go to sleep without thinking of that problem :P

Thanks a lot for your help!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question