I want to pick up a weapon only once

Hello,

I have managed to pick up a weapon and it automatically lands in my hand. But when I have this weapon, I can still pick up more of the same weapon. What I want is to not be able to pick up any more of the same weapon. Only one. The following is the blueprint section in the Thirdpersoncharacter BP:

I tried to set a variable HasPistol as true at the end of the node string and check it at the beginning of the node string. But it didn’t work.

Could you provide the screenshot of the code with your attempt implemented?The false output pin of a branch node shouldn’t be executed if the condition is true. In your next reply, could you also include the result when you read the value of the said variable to make sure it doesn’t get set back to false at some point?

That is the way to do it. Can you show the blueprint with that implemented and provide more detail on how exactly it’s not working? Is HasPistol bool not set correctly or when reading it picks up the item anyway etc.
(Use PrintString nodes do display the value of a variable or check if an execution thread is traversed)

Sooo.

I now have implemented this:

It prints out the value of the variable as true at the first time.
But it still lets me pick up the other weapons and does not print the variable anymore, no matter how often I try to pick up.
I intentionally added a print at the beginning and end of the node chain, but only the one at the end gets printed the first time I pick up, but never again.
Wait: I now got the first print to print. I forgot to link the white threads to it.

It sounds like this execution chain doesn’t get triggered as intended then, since you don’t receive any messages on the log after a single use. There must be another part in your code that lets you pick up an object.

That tells me that the chain with the print at the end (and also all attaching) is called only once, as I believe it is intended. So…

What is the actual issue?

The issue is, that if I go only by what’s printed, it only shoots off once. But it does pick up the weapon every time I click, as if the HasPistol parameter isn’t even checked at all.
I want it not to pick up any weapon if I already have it.

Like we both stated, since the print string node of yours at the end of the same execution chain doesn’t get triggered, it’s not the branch node to blame. The nodes connected to it’s false pin are definitely not being executed. But if you’re still not convinced, you can stay in your blueprint and test your game. You will see that the execution flow won’t reach that point anymore once you pick it up once. So look for other parts of your code, maybe even different assets. Maybe the picked up item is calling the function to be destroyed as well inside it’s own blueprint.

Wrong. It does fire as often as I want to. I mean it’s seasy to see, since the weapon on the ground disappears. So, at least the destroy actor node works.

Blueprint Runtime Error: “Accessed None trying to read property Current Weapon”. Node: Destroy Component Graph: EventGraph Function: Execute Ubergraph BP Third Person Character Blueprint: BP_ThirdPersonCharacter


This pic is from the actor, that I pick up.

Did you try my suggestion? There’s a way to know for sure than assuming.

I don’t know how to get code of the execution. I guess that’s what you need. But I don’t know what that is


This is with the print nodes that got me the stuff on my hud already shown.

You can use breakpoints, select something from that filter next to the play button’s row, right next to that three vertical dots, play the game and observe. But since you previously stated that the print string node only gets triggered once and never again, even if you press the correlated button, that means that execution chain doesn’t get triggered anymore. Because there isn’t any other direction it can go. There’s no fail pin or any other output execution pin in the nodes you use. So you can try my previous suggestion and look for other parts of your code which might trigger objects to be destroyed. Like I said, that might be happening in another asset too.

I slowly seem to approach the issue.
The interact event gets called in the pick up item BP and the 3rd person BP independently from each other.
I deleted the white thread from the first red node to the second node in the long node chain with all the print nodes in and the pistols on the ground still get deleted. So, that’s how I know now for sure:

The first time, the item BP interaction node chain gets triggered as well as the 3rd person BP one.
After that, only the item BP interaction node chain gets triggered

Yes, that was what I was expecting from the very start, like I mentioned in my previous posts :wink: Though what do you even trigger there? You seem to have everything you need already set up in the character blueprint. You destroy the interacted item and pick it up in the weapon form. I don’t think you need any code related to that in the item’s blueprint. Try disabling that.

I understand now.
I’m just asking myself won’t it be better to have the interaction in the item BP instead of in the character BP?
That way, my character BP is a little less filled and I can specify the interactions directly in the item classes. What’s the more steamlined way to do it?

No you don’t need to worry about that :innocent: you can safely handle many executions in a single blueprint. I can assure you that wether you implement that code in your character blueprint or your item blueprint, you’ll see absolutely no difference in performance. Though if you want you can still move it there for organization purposes.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.