x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do I implement Resource Gathering from Trees and Rocks

I am trying to figure a way to implement "resource gathering". For example, in order for me to build a hut or structure, I need wood. I need to gather that resource from the trees.

How would I script that so that when I hit the tree, it gives me wood. Then eventually the tree runs out of wood and falls over and then runs a destroy object on itself. The same thing with rocks, for mining.

I tried entering this question into the forums different ways and was not able to find an answer.

Thanks for your help.

Product Version: UE 4.11
Tags:
more ▼

asked May 04 '16 at 02:34 AM in Blueprint Scripting

avatar image

Sir_Slopolot
3 1 1 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

You need an inventory or backpack.

The legendary Tom Looman has a great post about this! http://www.tomlooman.com/tutorial-basic-inventory-system-in-blueprint/

There's a C++ version and a Blueprints version.

For implementing resource gathering, the simplest approach will be to have a distance check and a raytrace to check if the player has "hit" a resource structure. If they hit a resource structure, then add a number of resources to their inventory as guided by Looman's tutorial.

more ▼

answered May 04 '16 at 03:36 AM

avatar image

calembendell
447 36 39 67

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
  1. Data Assets: https://answers.unrealengine.com/questions/28236/when-should-i-use-data-asset-and-object-library.html There are differing schools of thought on how to handle inventory, but I would go data assets. As you're probably thinking about a multiplayer game, data assets can be very useful for binding ID's to database entries for persistence, AND you can put them in UE datatables for easy spreadsheet import/export!

  2. Get some tree models, populate map. When the player inputs at the tree, spawn logs. This is vague, but there are many implementations. For a action-combat model you would run a line trace from the camera forward vector, and if the tree was hit in that line trace (Check hit Actor class) while left mouse button was held down, you'd know the player wanted wood from that tree.

  3. For the tree running out of resources and "dying". I would have a variable set up in a blueprint: resourceAmount. Whenever the hit detection is done from 2, call a method on that tree object (call it updateResource or whatever). In that updateResource method if the new amount is

more ▼

answered May 04 '16 at 05:21 AM

avatar image

Dodgin
351 7 5 32

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Pally QLE does a great job explaining how to implement resource gathering. What's even better - he provides you with the entire project that you can pick apart that shows you how to do it. Check it out.

more ▼

answered May 04 '16 at 10:20 AM

avatar image

Nick Jackson
492 17 14 107

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question