After looking there doesn’t seem to be a sort node. In short, getting an array of actors and then order them by their distance from a main actor in the array from least to most. What I’m wanting to know is if there is a way to move array items down in the array ?
Are you storing the distance anywhere, is it a variable in each actor?
Haven’t decided.
I have something like that, cant check is that works now, but as far as i remember from weakest to strongest is a lot harder(more code) to do than from strongest to weakest.
Blue variable is a Spell Effect Actor and Green is Float which describe how powerfull this effect.
also i used custom macro which you would need to copy or make a gate system to mimic it functionality.
I can’t actually read it.
too bad, you know what that means - sit and think about how to resolve your problem.
I can see what all of the nodes are just fine.
So if I’m not mistaken using Insert will do the job.
It’s actually very easy to expose TArray::Sort() to blueprints, you could do it like this:
In the header, ArrayFunctions.h
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "ArrayFunctions.generated.h"
UCLASS()
class PROJECTNAME_API UArrayFunctions : public UBlueprintFunctionLibrary //replace with your project name in uppercase and _API
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Sort Array", Keywords = "Sort float array"), Category = Game)
static void fSortArray(UPARAM(ref) TArray<float>& TargetArray);
};
.cpp:
#include "ProjectName.h"
#include "ArrayFunctions.h"
#include "Array.h"
void UArrayFunctions::fSortArray(UPARAM(ref) TArray<float>& TargetArray)
{
TargetArray.Sort();
}
After that, you could sort them by doing something like the below, provided they have their distances saved as variables:
This will sort the actor array, so that the one with the shortest distance is at 0.
Thanks, I think I get the idea.
hi fellas!
this is another way to do it.
I will sort the floats of an array (in my exemple it is called “displayed stars distance to origin”) from minimum to maximum.
I created the variable “the following minor value” to handle the iteration process:
- first loop: i check every array element
- second loop: I find the minimum value of the remaining array elements and I store it. then i swap it with the loop index element.
Finally those distances are linked to an array of actors (“stars”) that I swap , reordering they too at the same time.
keep it up