How to get an actor's specific component with a component blueprint?

So I have a projectile that has a Box collosion component. I created a “CanHarm” blueprint component that applies damage to enemy on hit.

The problem is it kills the first enemy but after that the arrow(projectile) flies away from target (I have a custom homing projectile that’s not perfect but it worked without my custom component). Also there is one error message when I stop playing:

Accessed None ‘CallFunc_Array_Get_Item’ from node “Do Damage” in blueprint “Can Harm”

I think this is the source of the projectile strange behaviour. Also I tried “Is Valid” stuff with owning actor and the component too (so from “Get Owner” and after the get first item from array).

Accessed Nine ‘CallFunc_Array_Get_Item’ from node “Do Damage” in blueprint “Can Harm”

Do you mean “Accessed None”? That would be caused by the array “Get 0” node. If you have no items in an array (the length is zero) but try to get the first item, you’ll get an error. Item 0 is the first item, which is only okay to ask for if there is indeed at least one item in an array. So the bullet is likely hitting something that doesn’t have that component on it.

To fix this issue, put in a branch that checks if the length of the array is > 0.

I’m not sure that will fix all of your errors, but at least you’ll be able to solve the error message.

Yes it got rid of the error message just like the “Is Valid” node from the GET node. The projectile still behaves strangely tho. Nevermind I’ll find a solution. I wanted to know if I do things right and I guess I did everything right.

I have no idea if this is the issue, but have seen that error message more than I care too. When your in a loop manipulating an array, I have seen this message pop up, because the number of items in the array were being altered. In this case, it’s always when you remove an item. it feels as if that during the loop the value for the “end index” is not re-evaluated during each loop, but only set, when the loop is first started. (whether you use a For loop or For Each, makes no difference). I could find no “cheap” (i.e. little processing), way to force re-evalution at the top of the loop.

So there are really only two other alternatives,

  1. build your own for loop construct ( I mean let’s face it, a loop is nothing more than an IF statement that does some housekeeping for you) and make that a macro

2.if you are going to modify the contents of an array in a loop, have a temporary loop to the side, that you keep the index of the items to remove from the array, after the processing is done, just hooke the “remove” code up to the completed pin, and get after it.

To me, option 1 is the best way.

Hope that helps,

Bah, generally for what I was speaking of, the error message will also say something like, “9/5” as well, trying to tell you that you were trying to get the 9th element of an array that only has 5 elements

Well if this is so, how did we ever get the 6th Element without that message if the array only has 5 elements, and how did we get to the 9th element before the message was issued, if we only had 5 elements. i.e. there is no checking of the last index, at the top of the loop.

Now to your issue, yes this does pop up, in general what I found it means is that you have a null value, in the array, hence it’s saying “none”. I encountered this when doing Get all Overlapping actors, and the same for Overlapping Components. and using the return value to set an array. i.e. UE4 at 4.8.3, 4.9.0 and 4.9.1, is for some reason at times injecting a null into hte array coming back from the overlap request.

In order to circumvent this issue. I wrote a small routine to take an array, check for nulls, and return a new array, that has the nulls removed.

Hope this helps,

Uhh I haven’t cared about this project for a while. The goal was to make a tower defense game. When enemy goes into towers range attack it and stay on it until it dies or goes away from range and when that happens attack next enemy. Also I wanted every projectile to hit the target.

So I created array to hold enemies only in range. I behaved funny when the enemy died in range. Leaving the area worked fine I guess. But as I’m writing I’m thinking it’s not even a good thing to making an array. In Unity there is a onBeginOverlap and onBeingOverlapped :smiley: I don’t know the exact name. but UE4 has only 1 that checks if something came into range or not.

Maybe I’ll try your first method. basically you are saying that the built in array not built for what I want to do. It’s not that dynamic? Anyway thanks for the answer.