Out of scope casting? UE4.14 [update]

I’m writing this blueprint inwitch all the characters the player controls are put in an array and sorted by speed (smallest number to biggest). each game object has a turn speed and this blue print is supose to compare each one in the first array (made with the get all actors by class node) and put them one by one into a second, sorted array. my problem is that the speed var is being flaged as “out of scope” and as such, the arrays are both randomly ordered.

[Update]---------------------------[Update]

Okay so magically blueprints realised that “Basic character” is of the class “Basic character” and i don’t need to cast it…BUUUUUUUUUUUUUUUUUUUT now there’s a new, slight hick up. When making the unsorted array, it has two copies of the first actor now :3

][3]

Ok, the method you are using is O(n^3), so please do this instead:

For each position, extract the current character into a temp variable and then find the first character that has a lower time than the current temp character. Swap these two and continue.

Example pseudo code:

for i = 1 to length(A)
    j ← i
    while j > 0 and A[j-1] > A[j]
        swap A[j] and A[j-1]
        j ← j - 1
    end while
end for

HTH

The ‘IsSmallest’ variable does never provide correct information about if Ref1 is the smallest of all. It’s set to true when there is another array item found with a smaller turn rate.

First, I would set it to true before executing the innermost ForEachLoop (that is checking Ref2 against Ref1). Then, when you find a Ref2 with a smaller value, set it to false.

But as NoobsDeScroobs already said it is a bit inefficient. I would do something like this, inspired by [this][1] answer:

Notice that SmallestTurnRate, SmallestResult and IndexResult are function local variables.

thank you so much, i’m going to try that now and see if it works :smiley:

okay so my problem seems to be the title of this question again. no matter what, the array can’t get the variables from the objects in the array. (i can’t just link the “array elements” wiith “Target” like you have there)

My problem seems to be the title of this question again. no matter what, the array can’t get the variables from the objects in the array. (i can’t just link the “array elements” with “Target”

Two things–after your get all actors of class node, did you then cast to that actor class before adding it to the array? I believe you need to do this. Second, do all of your actors derive from the same master class that has the speed variable? They all need to derive from the same master class to get the variable using this method.

What type is the array element? How are you accessing them?

Out of Scope means that you are trying to access something that does not exist in your area of the code. Are you sure it is the speed var? Post your error code please.

for question 2, yes they are all the came from the same, master class. as for question one, there isn’t an easy way to cast all the actors. the node puts them straight into an array of actors.

136681-ss4.png

sorry, didn’t notice. it looks like i found the problem (it’s the image that is titled ss4

136681-ss4.png

) when the blueprint gets all the characters, it puts everything into an actor array. if i try casting any of the elements in this array, i get the “out of scope” warning for the variable when i hover over it in the blueprint. the problem is that there is NO ERROR. the only thing that tells me that this isn’t working is the fact that the sorted array isn’t sorted at all

what’s more is that i can’t take the turn speed directly from the array element pin because blueprints just sees the array as an array of actors and not as an array of "basic character"s

Instead of adding the actors manually to the CharacterList, why don’t you just set it from the result from ‘Get All Actors of Class’? Perhaps BasicCharacter3 is already in the array (for example as default value) and then added a second time in your BeginPlay graph. That would be my first guess from the screenshots.