Getting/setting actor locations not working

I have a ball that spawns every 5 seconds and then flies through the air. Think of a golf ball being hit at a driving range with an automatic ball dispenser. I want to get how far the ball goes, so the idea is to have an actor where the player is (I guess I could just use the player but whatever), and set its height to the ball as it flies through the air. Then measure the distance between the two.

So see pic for blueprint. On event tick, I am just updating a widget’s text to show the ball’s z position. I then want to set the other actor to that z position. The problem is, as soon as the ball spawns, the actor by the player moves to a seemingly random spot and just stays there. It doesn’t move as the ball goes up and down, etc. Also, the widget text is set when the balls spawns, but doesn’t change as the ball moves.

So it seems event tick is running because if I do a print I get them every tick. Just the value of z does not change of the ball as it moves for some reason.

Any insight? The ball moves when it is spawned from a forward vector added to Add Impuse

hmmm Could be a few things. My first thought is that the Get Actor nodes arent finding the right actor. If it were me, Id use a ‘Get All Actors of Class’ node, feed the array output into a ForEachLoop and then execute the function on the output. Even if theres only one instance of the class you want, youll have the peace of mind that the software has captured ALL instances of it.

On the Get Actor node, you shouldn’t use nodes like that on Event Tick, its super slow even with only one instance of the actor youre trying to capture. I mean, unless you have the free ms in your frame budget. For something like this, a timer is ideal. I just whipped up some nodes to show you an example of how I might do something like this:

So youve got the player, the ball, an actor with text in it, and an actor that rises up to match the Z value of the ball - so you could put this in the ball actor, or the actor that rises up (just change the target and Z location in the Set Location node). Should work fine!

My snippet doesnt set the text in the widget actor, but that should be trivial and can be done at the Set Z Loc event, though doing it by getting the class, casting to the class, getting the widget, then casting to the widget class in a timer set to loop at 0.0 is just as bad (probs worse) for frame budget than a bunch of Get Actor of Class nodes, so maybe capture it as a variable too - or do it in the widget actor and set the text with a similar timer.

Other possible reasons its not working could be that Event Tick is turned off for the actor in your screencap. Its on by default, but its a possibility. Definitely drop by again if the issue persists! I hope this rambling comment helped XD

Thanks for your time and effort on this. I will try and play with it some more and let you know what happens.

I do know event tick is already hooked up…because if I have a simple print in there, I see them all come up every tick. Also, the problem exists when the 1st ball is launched, and is the only one in existence. So not sure why the event tick would have a problem finding itself, especially when there is only one. It just doesn’t seem to pick up the movement.

Maybe if I used a character instead and moved it via the move input events it would work. Anyway, will let you know what I try and what I can get working, or not.

Ok I’ve really simplified things for testing. When the club hits the ball, it calls testLocZ function on the ball. There, I simply print ‘I’ve been hit !!!’ to make sure it gets called correctly. From there, I try to set timer by event as you suggest to simply print out “printing z location”.

What happens is, on hit I see “I’ve been hit !!!” as expected. But I don’t see “printing z location” after. I tried using function name instead of event but that doesn’t work either.

So now it seems I am back to where I was originally. I added a time of .1 to set timer event so now I see the values comes as expected. But they are all the same. Same as originally posted.

Ok I got it working…newbie error. When I created the ball blueprint and added the ball mesh, it added it as a child to DefaultSceneRoot. I got rid of that and made the ball the root and now it works.

Maybe you can help me with one other thing. The auto ball shooter fires every few seconds, and the ball exists for 30 seconds, and I only want the distance to be measured for the most recent ball hit. The ball has a variable called ‘beenhit’. So I only want the most recent ball to have that variable to true when it’s hit. Should I do a get all actors thing first, and set all their variables to false, then set true on the current one? Or is there a better way to do that?