Can someone please help with getting an actor reference from an array based on location?

Hey all. By now I’ve posted this to the ue4 sub, it’s been on the answerhub for about a week and I’m honestly at my wits end and super upset at this since I can’t progress any more until I solve this.

I’m trying to make it so players can interact with the HISMs that are generated in the world. I do this by a HUD menu that will popup with the relevant buttons depending on what you’re interacting with. This works pretty well. Right now in the process of resource collection, things like wood, gold, etc, etc…

I have a simple setup to chop down trees and collect the wood. This is used with an event generation master that will spawn a BP Actor to act as a specific event when needed. It will destroy itself when it is done.

My problem is I need some sort of way to re-reference the actor if the player did not finish chopping down a tree, or went and did something else, or was interrupted for whatever reason. I’m attempting to get the player, tree and the cut event actors’s location and check them against each other but it doesn’t seem to work.

  1. Player interacts with tree.

  2. HUD prompt appears.

  3. Chop wood button is hit.

  4. Event master spawns chop wood actor by getting the hit HISMs location.

  5. Tree is chopped down wood pops out every “chop” this works perfectly with the third attempt(as long as the player stays in the exact same spot) and the other two it will only work once.

I am trying to get the players location, the HISM’s location and the cut wood actors location, compare them if similar then don’t spawn and use that one to de-increment the trees’s health.

(1st and 2nd attempt) - (Second branch = True)Any further attempts will spawn another one, but since I’m for looping all actors of class it drops wood exponentially more often. 10, 20, 40, 80, 160, etc, etc… So infinite wood then game crash.

(1st and 2nd attempt) - (Second branch = False)It will not want to spawn another for unknown reasons, and it won’t go off the first spawn as the array length is now greater then 0. Unless the actor is deleted, but since multiple people can chop wood it’s just assumed this would always be greater then 0 after the first spawn.


(https://imgur.com/a/2fo51z0)




The closest I've gotten by far is using a sphere trace to detect if the player is overlapping the tree HISM. The problem is a chopped tree is a log on the ground; so a sphere trace will never cover the whole thing unless it is gigantic. which is just gonna mean I can't chop any trees close to each other at all. I need some sort of way to trace along the trees entire collision and then if it has a cut wood actor overlapping(and a player within x range) use that, exact one's functionality. If it does not have an overlapping cut wood actor, spawn a new one so you can use that one's functionality instead.

Where mine fails is it will just spawn a new one if the player walks a little bit down the tree's length as it's checking for overlaps in a sphere not the tree's collision.

Any help appreciated.

@PerCat I’ve only skim read this, so maybe I’m way off target, but: Why not make the tree a BP which can handle animating it’s ‘downfall’ in response to a BP interface call?

That way you don’t have to manage separate objects, you just have to keep sending the tree BP the interface call.

Well think of this “project” as some sort of mix between rts and rpg, each player controls a small group of pawns and they compete for resources/objectives. The levels are fully random with the host deciding how it’s all generated. There can be thousands of trees or 6, or anything inbetween.

So using instances on this is my best bet to save on draw-calls for resources. A bp that would switch out would work alright but potentially could be lots of draw calls, depending on how the players play. And there is a lot of level events that are already in place that would make that switch suck as I would have to rework quite a bit to have it work with instances and bps.

So I can but it would suuuuck, so I’m really hoping what I’m trying to do is possible, but idk cause of how difficult it seems to be so far.

@PerCat Did you know you can instance BPs like foliage now? ( maybe that’s relevant )…

Aside from the fact you can instance BP with foliage since I think .19 or .20.
The way you are going about it and how you frames this question is just odd.

If you want an event to stop whatever it is based on distance, create an appropriately large shape and detect the End Overlap event to put a stop to whatever interaction was occurring.

You definitely will not find a way to get a reference based on location since location is always updating and even with an array map you have nothing that is constantly updating the data to keep track of the location. The overhead for that is probably almost as bad as not using instances (depending on number of actors your would have to trace to).

If you really cant use instanced blueprints, the best way would be to spawn a custom invisible mesh to use for the overlap detection. You just spawn it around the character, and use it to determine when/if the player exits the area via the same end overlap.

How does that work? I honestly didn’t know you could… I thought each individual bp would be a draw call?

[USER=“3140864”]MostHost LA[/USER] sorry but I think you may have misunderstood my question a little. The resources wouldn’t move any, I already have it working mostly I just can’t re-get the reference after the blueprint runs the first time. So after a tree has been chopped and it has fallen to the ground(some fancy particles play and it’s swiped out for a log HISM), the player then interacts again to chop wood from it. This is where my struggle is, it will do a sphere trace(lets say 100) to detect if it has already spawned a cut log event, but the sphere trace doesn’t cover the whole log if its 300 long, so then it will spawn another at the new hit location.

I need the function to trace the instances collision? Like a begin overlap, but, it would be callable? Some sort of way to get a trace the exact size and shape of the instances collision, I just don’t know if that’s actually possible.

@PerCat Like this. But you don’t get the benefits of instancing, not possible of course:

@ClockworkOcean I think this went right over my head, why would I instance a bp if I don’t get the benefit, I don’t understand? Cause then the hisms are better, no?

Been out of the forum for a while. Can you keep a reference of both the instance of the hism and the blueprint spawned for actions at the same time that you begin those actions? That way when you cancel you just use those references. Interface communication preferable.

So, to recap, the issue is that the log is being cut again after it already has been cut in that same location. Correct?

Thinking out of the box a little with some pseudo code.

Player cuts instanced tree.
Instance of foliage removed.
BP of falling log spawned.
Hit events on spawned log kept track internally to the log BP.

Because no instance is avaliable at this location theoretically following that pseudo code logic you wouldn’t be able to re-spawn a log.

If this doesn’t help, could you give us a visual representation (a short video) of the issue? For clarity and brevity…

@**NotSoAccurateNo1 **thats the problem, I don’t know how to reference the hism.

It’s tracking the players actions on specific hisms, this time a fallen log. So when a player “cuts” a log it will spawn a bp actor that would spawn the amount of wood after the cut is done. Buuut it does a sphere trace to detect where the log hism, cut actor, and player are. If a cut wood actor isn’t on the log it will spawn a new one but the player can just walk to a different portion of the log and make a new cut.

But the new cut should increment off the one already spawned. And then it should destroy the hism and itself when the log is all the way chopped. I can’t figure out how to trace along the hisms collisions or something because a sphere will never fully cover the log unless it’s big, but what if there are multiple fallen logs in this sphere? Then you can’t chop the other ones since it will always detect a chop wood actor.

I don’t know how to keep the reference I attempt to add it to an array but the player can just chop a tree walk to a different one and do it again ad infinitum. So I’ll never know what the location, or index of the hism is. SO I need to get by location, except the only way is a sphere overlapping actors which is terrible as it has huge drawbacks.

[USER=“3140864”]MostHost LA[/USER] Yeah that’s basically what it is. I would just have the fallen log be it’s own bp but I’m trying to save on resources and there are many ingame events that could cause a tree to fall and turn into a log outside of player control. So I want to keep using hisms to cut down on draw calls. So I spawn a bp actor that isn’t visible on location of the log and get the player interaction with the hism added to that, it works if the player doesn’t move and the sphere picks up everything’s location.

The problem is it all falls apart if the player moves and makes a different cut, goes to a different log or anything else really. I need the sphere overlap actors to be nixed as it doesn’t allow logs that are close together to be chopped and it never fully covers the log allowing players to keep spawning in. Somehow need the overlap actors to be with the hisms collisions.

“The problem is it all falls apart if the player moves and makes a different cut”

I would change the code so that it doesn’t check for location, but disables the whole BP on End Overlap of a player class.

However, if you really want to keep track of locations, the best way is to use this system here
https://docs.unrealengine.com/Images/Engine/Rendering/RenderTargets/BlueprintRenderTargets/HowTo/FluidSurface/FS_Begin_End_Overlap.jpg
doc page:

Read on, or rather implement it, or better yet, look at the content example. it becomes clear how it tracks position over time.

That said, it’s stupid expensive when the location on the log doesn’t really matter to you. you have the log. if the character is anywhere within it (custom capsule collision covering it) you allow the chop. the moment the character walks off you stop the chop, start a timer for dissolving/removing.

it should be more then what you need. though maybe the issue is actually on the instanced mesh re-spawning side?

[USER=“3140864”]MostHost LA[/USER] But how do I check for the meshes overlap then? If I just give it two different collisions how could I differentiate between one and the other? I don’t want players to be able to walk through the fallen trees but I could just add a larger capsule component to the base mesh.

You can have 100^100 custom meshes set to hidden in game with custom collision that still provide reaction via code.

Basically you literally just add another capsule component and set the collision settings to overlapp all.
It wont affect the mesh collision for the tree either, which should be handled with simple collision within the FBX and automatically made part of the mesh.

Performance wise it may be best to utilize the in engine shapes and components, but if you keep your custom collision mesh simple, and if you swap the normals around, you wont even see the mesh anyway (except it costs to try to render so actually hide it).