I have a problem with my inventory system. First some information for what I want to do:
What I want to accomplish is to have a blueprint which holds all information for that “ingame-item”, including the StaticMesh, Title, Attributes and so on.
Now also I want to be able to pickup and drop the item. This leads me to the idea to disabling collision and set it hidden when I pick it up. Then I can switch this back when I want to drop the item again.
As far as I am I can grab the item and could also drop it. but here I have the problem:
After I disable the collision and set the item to “hidden” when grabbing it, it takes like 2 seconds and the Actor disappears from the “Scene Outliner”. So I can´t drop the item anymore. My guess is that my Actor got destroyed within the period between picking up and trying to drop the item.
Now I´m using my collision disabling and hide on the static mesh, instead on the whole Actor. This avoids the removing of the Actor from the Scene after some time.
Is this some kind of bug or just wrong use of BP from my side?
Great question and thanks for the answer below. It would be nice if someone could explain why your first approach didn’t work. Are we not supposed to set actors as hidden and disable collisions? Why does that cause actor destructon. Anyone info from folks at Epic on how this should work would be great.
Yea, I think I was having a related issue earlier today in my game. I was disabling collision on my character’s capsule component and the engine would just randomly destroy my actor and trigger the OnDestroyed delegate I had setup. I would love to know why the engine thinks its a good idea to randomly nuke your character out of the blue. If I hadn’t just happen to have an old breakpoint on the OnDestroyed delegate I don’t know how I would have ever figured out what was going on.
Gravity will still be applied to your actor, despite collision being disabled. The fact that collision is disabled is ironically what causes it to be cleared up. It no longer collides with the floor so it begins to fall. Actors below a certain Z height are automatically cleaned up.
In addition to disabling collision and visibility you’ll need to call SetSimulatePhysics( false ) on any mesh components on the actor.
Can’t you just create a container class that is a container for item(s) that are picked up and placed in inventory? Then all those calls to disable collision, physics, and hide can flow from the event of adding item to container class. Dropping item(s) switches it (perhaps add a static switch or bool), and changes those hide/physics settings back to item(s) interacting with game world as initially intended (when not in inventory).