Resource gathering help?

Hey all I’m working on a resource gathering system for a rts project I’m working on. And any tips or help to how to approach this would be great.

  1. Select Unit.
  2. Right click resource.
  3. HUD pops up; tell unit to mine.
  4. Unit walks over, when he reaches the destination a boolean sets the mining to true.
  5. HISM destroys itself and drops rocks.
  6. Unit can now pick up rocks and do what ever with them.

My problem with this system is I’d like to be able to make gathering resources take time, and if they are interrupted they can walk away and come back to finish up.

I’m using booleans and overlaps with the actors’s collisions. This doesn’t seem to be a “good” way of doing this as being near other rocks will also mine those ones. I could make the collisions smaller but then for misshapen rocks I would have to use a complex collision which makes the meshes more expensive.

Since there are lots of rocks, trees and other things on the map they have no functionality; they are just HISMS. So most of this stuff is done between the unit, player controller and the hud.

I think maybe have some sort of way to destroy a specific HISM and place an actual blueprint down when a player or unit selects a rock to mine? I could continue using the HISMS and tags to determine stuff as well? I’m really trying to find the best way here to make resources work well.

  • Takes time to collect.
  • Will drop relevant amount of yield. Trees drop wood, rocks drop stone etc…
  • Can be finished if interrupted at certain point.
  • One at a time.
  • Not expensive.

Ideally I could just have it setup like stronghold or something, except I could still tell the units to cut down specific trees or whatever if needed.

Any help appreciated thank you.

Hi, maybe I can give you some pointers.

  1. Do a Linetrace from your RTS Camera check if it hits a unit, if it does save the unit in a variable for later use as “selected unit”.

2/4. On Right Mousebutton again Linetrace from your RTS Camera, check if it hits a resource, if it does tell your “selected unit” to move there (moving there would be handled in the Behaviour Tree of the AI that controls the unit, basic AI Tutorial Behavior Tree Quick Start Guide | Unreal Engine Documentation). You can use a “Move To” Node and input the resource Location. You can also specify the acceptable radius. If the unit reaches the resource let it start gather the resource.

As for taking time to collect you could use a delay Node after starting to gather the resource. As for the next to points if you don’t have too many resource objects you could use Actors as resource objects (then you could have a variable inside the Actor where you would specify the resource type and a variabe that saves the progress, to later continue gathering). If Actors won’t work (chews up too much performance) maybe you could use Instanced Static Meshes and have a dict that maps between a Static Mesh and a resource type. Then when your unit starts to gather resource you could replace the Instanced Static Mesh with an Actor (theres a “Remove Instance” Node) and replace the Actor again with an Instanced Static Mesh when not needed anymore (theres a “Add Instance World Space” Node).

For an automatic resource gathering you could use something like a sphere trace to get the nearest resource aviable, check the type and then move there.

Hmm, your first points are almost exactly how I have mine setup. The other bits seems like a good way to handle this, I’ll have to do some testing and update this post, thanks!

Ahh okay my bad I wasn’t clear enough in my post 1-6 is already done. My way of selecting units and resources is almost exactly as you describe it.

But the other points do seem like a decent viable way of doing these things, I’ll have to do some more testing for sure. Thanks!

instead of a trace you could also use the get hit result under cursor which is basically the same as a trace from the camera through the cursor and into the world but in a much simpler package.

What if you use a subscription system instead of the overlap? (or a combination of the two)
The unit is ordered to gather resources from resource spot. Now tell that resource spot to bind an event to the unit’s gathering event dispatcher. Call the event dispatcher on the unit once gathering is finished, then logic can happen inside the resource spot. You can also let the unit subscribe to the resource spot instead, and have all units gathering at it receive resources at the same time. Hope this helps.

I do a get hit result under cursor for objects > break hit result > hit component > tags,(wood, tree, gold, etc, etc…) then use that to create/destroy a hud that will pop and you can then select the options.