Hello I just started a few days ago with UE4 and I do not have any programming skills so I do not know most of the terminology.
I am trying to create a small village simulation.
I started by creating a storage system (a shelf so far)
that can store a certain amount of food.
Once a character’s hunger is over a certain value, he will walk to that shelf and trigger
an event which tells the shelf how hungry he is. The shelf checks how much food there
is in the storage and returns the given value (max 100) or the largest amount it can give.
Now my problem is that this only works with one shelf and one character
and If I use 2 or more only the first chars hunger is reduced.
I would like to expand it so that the characters :
1)check for the closest shelf/ can own their own shelf
2)separately interact with characters.(so each gets their own inventory.
Thank you for your time.
Also Ideas for this project are always welcome
In order to give the villager nearby food you will need to get him (probably with a hitbox and the “Event on overlap”) so you get the specific villager.
To get the closes shelf you could search for all existing shelf actors in the map “Get All Actors of Class” and check which one has the closes distance in relation to your villager.
And to give each villager it’s own inventory you just have to set it up in the blueprint and spawn multiple of the same object in.
Thanks for the reply.
I made an array to find the closest shelf and the events now use the instigator by using cast as nodes. So now I can use multiple shelves and villagers.
Get all, just get the distance and pick the closest. Then walk there and request food.
Nothing should happen when you request the same thing from two villagers.
The result from “Get all actors from class” will provide you with an array of (in this case) shelfs. You can then once you determined which is the closes set this to the one you walk to.
And for shelfs take an input to your custom event for the villager (you also might wanna do this via a function) and you can get rid of the variable and simply use that line provided. In villager give “reference to self” to that function as that variable and you’re ready to go.