Best way to implement resource gathering?

Hey all!
I’m trying to figure out the best way to implement a basic pawn, resource gathering system.

As of now the way I’m trying to do this is I right click on say, a rock; context menu pops up. I click “Mine”.

Button calls function to the player pawn, that enables “Mining?” bool and then has them walk over.

On overlap with rock’s collision the actor spawns stone resource on the ground and destroys itself.

It’s pretty simple yet convoluted, I’m trying to make it simple enough. yet do it’s job well. End game I’d hope for around the same thing I currently have.

Select your player > click rock > menu pops up > select mine > pawn walks over plays mining animation > rock durability ticks down every animation loop > once it reaches 0 destroy actor and then spawn the resource.

My main problems so far, is for some reason my navmesh won’t update after the actor destruction. So my pawn can’t pick up the stone. And now there’s an empty spot on the ground that I can’t walk through.

And then I can’t reference the location of a destroyed actor after it’s destruction, so the stone actually gets spawn on overlap as well.

And also where would the best place to store the functions be? Inside player pawn? Player controller? Hud? Or the resource being mined? I thought a bp library would be great but I’m referencing a lot of different things to make this work so I figured a library may be the best. If there’s a better way to do this or any good tuts out there, Any help appreciated.

  • First problem: Try switching runtime generation of navmesh in project settings to Dynamic instead of Static.

  • Second problem: I don’t fully understand what you mean here, why would you want to reference its location? if i understood correctly though, a better approach would be to hide the mesh first, make sure you spawned the resource then destroy the resource actor.

  • Third problem: It’s totally up to you but i like to approach things like this in a way in modular way that is easy to work with and also easily remember if i stopped working on a project for a long time. So maybe i would make a ‘Mining’ component that gets added to any pawn that can mine, and anything that can be interacted with by the HUD would share an interface called ‘Interactable’ and anything that can get mined has a base class called ‘Resource’.
    When my HUD interacts with anything (something that has the Interactable interface) i’d show a context menu based on its type (Resource) and if a button is clicked i talk to the component that handles this sort of Interactable type which is the ‘Mining’ component and tell it to go mine that resource and in the ‘Resource’ actor, when durability hits 0 i would spawn the Pickup and destroy actor.

That way allows you to add functionality easily later, for example if you wanted to add more resources that can get mined, or maybe Crafting Workshops that when interacted with it would talk to a Crafting component on the pawn, etc…

Your first and second problems were both the exact solutions I came up with, makes me feel a little better to know that’s a good solution.

And yeah I was thinking component might be good as well since I plan to have everything else attached to specific equipment anyways.