Well, I’m trying to create a logic that when my character has an item in his hand and tries to pick up a new item in the scene, the one in his hand drops automatically as soon as he presses to pick up the new item. But I’m not succeeding at all, I’ve tried a lot of things but none of them worked, could someone please give me a light?
How are you doing the pickup in the first place?
How do you know which object to pick up?
How do you attach it to the character?
Do you have additional state to track what you’re currently holding?
Second, what have you actually tried to undo whatever you did in the first case?
“many things” could mean … many things
I already collected it in two ways in the character’s blueprint, which caused an error that I could only get the most recent item added to the scene, and also in the blueprint of the item that occurred the case of not being able to communicate the items with each other (an item did not remove what was already in the character’s hand). Excuse me if this is my stupidity but I’m very new to unreal.
The condition I’m sure I’m using wrong because I know how to change its value after collecting the item, but I don’t know what to do afterwards, the only thing I know how to do is when the character Press E again to release the item, I should put a limiter so I could only do this when overlapping a new item but I don’t know how to do it.
Your explanation makes no sense. There is no error that “you can only get the most recent item added to the scene” in the Unreal Engine, Unreal Editor, or default game templates.
Where did that error come from?
Typically, when you “pick up” something, you will have some kind of trigger volume that enables an interaction, and you’ll set up the interaction to run some code, and that code will target the object, probably attach it to the player character as a child actor, and turn off physics simulation on that object. You will frequently also set some variable on your character, or maybe player controller, to whatever actor you’re currently holding.
If, inside the “pick up” handler, you find that there’s already a “currently holding” object, then you should first detach that actor from the character actor, re-enable physics on it, and let it go (so it can fall to the ground); then you run the same “pick up and attach” code that you run normally for picking up another object.
How do you currently detect that there are objects to pick up? How do you decide which object is pick-uppable if there’s more than one in range? How do you exclude the object you’re holding from whatever in-range detection you’re doing?
All this code is likely the place where you want to put the “let go of the current item” logic, but it’s impossible to answer your questions if you don’t tell us how you’re actually arranging things.
I created the toy item and the medical kit item, both have the same collection function by collision box only when the player is inside the box I activate the entrance to be able to pick up the item and when it comes out disabled, basically the default for collecting the entire game, but I do it all in the blueprint of the item just designing for the character.
I want to know how to tell the character that he already has an item so that when he picks up another one in the scene, the one in his hand drops.
I’m sorry for my english it’s not my native language
In general, you’ll want the character to pick up the item, you do not want the item to have to tell the character to be picked up.
When the player enters the collision box of the item, the item should add itself to a list of potentially pickable-uppable items in the character. Easiest is to use an interface that you implement on the character. When the player leaves the collision box, remove itself, again through the same interface mechanism.
The player should update the HUD displaying the message “Press E to pick up (thing)” when the list of pick-uppable items is not empty.
When the player gets the “pick up item” interaction (note, player gets this, not item!) the player first looks at the “currently carried” variable, and if it’s some actor, detaches that actor. It then looks at the first item in the pick-uppable list, and attached that as a child actor.
When picking up an item, the player should also turn off collision on the item being carried, and it should remove the item from the list of pick-uppable items. When dropping the item, turn on collisions on it again. Alternatively, you can filter out “the currently carried item” from the list of pick-uppable items when deciding what to display and how to react to pick-up interactions.
I think your English is probably good enough, but maybe you’re not particularly used to developing software and asking for help – I’m having to try to read your mind here, because you’re still not giving a lot of information about how you’re currently building the system, or what the real problem is. “Knowing whether a player carries something” is as simple as having the player update a variable of what’s being carried, when picking up or dropping something. When you say you “tried many things,” was that one of the things you tried? I don’t know, because you didn’t say what you actually tried!
Also, often, when trying to formulate a real question about what you actually need to know, the solution comes from working through the question, and you don’t even need to ask the question in the end! This is a secret super-power of working to ask good questions