i have a annoying problem right now and i hope someone can help me.
Im working on a rts style game where i can assign units to buildings, they start working return the resources and repeat.
I used bpi’s to start the events for example if my bulding is full i call the bpi and that tells the worker that is assigned to the warehouse to come and pick it up.
However i have a problem with referencing, ive set up a bpi and called a function works in warehouse, it gets called whenever a unit starts working in the warehouse and it passes a reference to self(the worker) towards the building, so the building can use it and call another bpi that triggers the pickup logic for that specific worker. This works.
Now i cant figure out how i can get a proper reference to the specific actor instance of the building, thats why i used get all actors from class here ofc thats not a option because i will have many building.
I thought about storing all building references in a array but i have no idea how i would know the specific index that i need for each instance / reference of the building.
In this case a Fishing hut. the worker thats assigned to the warehouse has to go there and pick the resources up but to do that i have to reference the specifig building instance.
Get all actors of class works here because i only have one fishing hut placed in the world.
Would that work if i have multiple buildings? Lets say i have 2 fishing huts but one is further away would my worker ever be able to pick up the resources of the 2. one ?
Imo you need a manager that is able to receive and dispatch messages to the registered buildings. Then buildings would only be responsible for their respective tasks and do not need to know about the other buildings. So warehouses will only collect where manager says and huts are only responsible for producing and informing the manager if it has enough to be collected.
The thing is the worker should only go to that building when its full.
So lets say i have 2 fishing huts whenever one is full it calls a bpi that triggers the worker to go there pick it up and bring it to the warehouse.
If i understand it correctly find nearest actor would make my worker go to the nearest hut collect everything bring it back and then repeat.
A manager can just be an empty actor placed in the level that the buildings talk to via BPI, when a building is ready for “harvest” it sends a self reference to the manager that gets added to an array, then finds the nearest to a worker and sends the reference to the worker.
When a building runs out it triggers a function that removes itself from the array.
That way when you have huts 1 and 2, they’re both full, nearest is 1, it sends ref to Hut 1 to the worker, when that runs out it gets removed from the array and only hut 2 remains, and that becomes the nearest.
This is an example of a “Guard” manager from my shooter game, when the player is out of range, the guard calls “Repopulate” and adds itself, basically saying “Hey, I’m free”
Then when the area needs a guard, instead of spawning one, it takes that idle guard and teleports them, then removes them from the array.
(The blacked out one just spawns a new guard if the array is empty, blacked out because irrelevant)