How to sort a hit array by instance index?

Hey all I have a dungeon generator I’ve been working on for a while, it’s using hisms for everything and I’m attempting to simply brute force doorways spawning by getting random walls, sphere tracing them to check for any walls that are “good” and then there is a chance it get’s replaced by a door.

I’m using streams for everything that way a player can potentially have the same world from a seed they like or whatever. For some reason I have slight variance in door spawning locations on the same seeds. I figured out the multisphere trace seems to randomly sort it’s hit array.

I want to take the array and sort it by index but I have no idea how to sort an array by index. If anyone has some ideas on how to fix my problem that would be great.

I just need the hit array of instances to get sorted, preferably by index, or any, real, predictable way would be fine. My problem is multisphere trace doesn’t like to put hits in the array the same, even if the trace is in the exact same location.

Thanks!

You can use min / max of array + While loop.

The first loop creates a random array. While loop keeps picking min integer for as long as there anything in the unsorted left, adds it to a sorted array and removes it from unsorted. This prints the sorted from min to max value.

308338-annotation-2020-07-28-165124.jpg

Do you know how I would go about getting my hit instances into that array sorted?

Edit: This was all I was able to get so far

Don’t sort arrays in blueprints: readability and performance of such implementations will be worse than C++ TArray. Also you can easily make mistakes.

Check TArray documentation :slight_smile: TArray: Arrays in Unreal Engine | Unreal Engine Documentation

Write a functon to get the max index. The write another foreach which repeatedly finds the max and removes it, putting it in a second array.

I posted a screenshot of what I got up above, I’m away from pc right now but my problem is re-adding the instance I need to a now sorted array.

I don’t know c and performance isn’t gonna be an issue, this is pre-gen type stuff that won’t effect gameplay

It’s like Everynone says, you need to put the right thing in the array first. Then make a MAX func ( or min ), then do:

but my problem is re-adding the
instance I need to a now sorted array

Your first problem is getting the correct values into that very first HISM Indexes array. Think about it. You hit some instances with MultiSphere Trace but here you’re adding just 0,1,2,3 indexes of an array - these are not HISM instance IDs.

Instance IDs come from the Hit Item when you break the Hit Result struct - and you probably already have it.

Don’t sort arrays in blueprints:
readability and performance of such
implementations will be worse than C++
TArray. Also you can easily make
mistakes.

Also this. While true, sure - why reinvent the (really well oiled!) wheel, this answer feels like a generic stack overflow quote. An answer to ‘how to do it in blueprints’ can never be ‘don’t do it in blueprints’.

Don’t like blueprint spaghetti? Go eat the a, b, c++ alphabet soup. :wink:


Also, the Extended Standard Library plugin has sorting afair.

It does, very efficiently. But I discovered it also wont package without a compiler… :-/

Oh, that’s a bummer then.

Yup, yup. Got it! Thank you much man!

lol, I’ll just keep watching your blueprint experiments.
“I don’t know C” is not the issue here. It’s better to get acquainted with it to avoid problems like this.
Btw, Extendernd Standard Library won’t help you: you can’t specify sofrting function in it :slight_smile:

Oh yes you can… :wink: