Procedural Size Variation help needed

Hi,

So its been a few years since I used UE/Blueprints and for the life of me I cannot work out a more efficient way to generate a procedural sprite selector that has 2 potential sized sprites.

Let me explain. So lets say I’m making a Street scene. The Street contains fences (512x512), houses (1024x1024) and each block contains 10 units to spawn (any unit could be a fence or a house). I have made a Struct containing all my Names (Fence 1, Fence 2, House 1, house 2 etc) for a total of 12 potential assets. Now in a new BP add my Struct as an ENUM variable 10 times and make them public (called “Enum Buildings 001, Enum Buildings 002” etc).

So what I am currently doing (I know this works but it does not seem like the most efficient way to do this) is using a switch from my Enum Building 001, I am then adding a ‘Paper Sprite Component’ and ‘Setting sprite’ for each output of my Enum switch.
Next, I’m checking if the first Selected Enum = 'Fence 001 or Fence 002) and if it does I am setting the transform of the second Enum (Enum Building 002) to x512, if false it sets the it to x1024. Nice and simple. but this becomes a right mess now that I have to check each iteration for multiple results… for example, If 1st is ‘Fence’ spawn 2 at 512. if 2nd is ‘Fence’ spawn 3rd at x1024 but if 2 is ‘House’ spawn 3rd at x1536. If the 1st is a 'House" and the second is a “House”, spawn 3rd at x2048. and so on and so forth. as you can imagine by the time I get to the 10th, this is gonna be a nightmare.

Here are some screen shots to help illustrate the issue…




I hope you can see what I’m talking about. Please bare in mind that it has been a good few years since I have done BP and I was never an expert :wink:

Thanks for any help.

You need to store the distance along with the sprite info. So you could have an array of structures

image

Then when you place a sprite, you can move along by it’s size.

Also, it all seems a bit fixed, don’t you want some randomness in there?

Hi @ClockworkOcean, thanks for the reply, but I’m not sure how this would reduce the mess that I currently have. Could you elaborate on the Construction script section please?

I understand about adding the variables in a struct, so are you saying I create 2 structs (1 for the 1024x1024 and another for the 512x512), then I assume I’d use a for loop in some way to determine what is drawn and shuffle it along by the assigned struct 'Distance", is that right?

Thanks

Yes :slight_smile:

Whatever piece you lay down, you can increment your position pointer by the amount ( in the struct ) and you know where to put the next piece.

What confuses me about your setup, is it seems to be for just one fixed street.

Surely you want it to be random? ( ish )

Ahh yeah sorry I forgot you asked about that. It’s a bit of an unusual set up but we already have a pre designed level and some of the interactable buildings need to be placed at specific locations, now, if it was one or two I would have just dropped them in manually but the designer wants about 50-60% of them interactable in some way. So for speed of the build I thought it best to just construct the street in this way then we can go in and specify the buildings that need to be engaged with.

So you can drop the interactive buildings where you need them, and then use a BP to fill in the gaps?

That would be my first choice but he wants the ability to have it all constructed in a single BP, then for example… select slots 3, 12, 13, 24, 26, 28, 33, 80 etc and make them interactive buildings

1 Like

Ok, still possible.

I’ll knock something together, but I don’t have any sprites, so it’s a ‘concept’ piece… :slight_smile:

1 Like

Ok, so this is it. It’s a bit messy, and I used static meshes instead of sprites.

We have the ‘sprite spec’ concept again, which is a sprite ( in my case a mesh ), and the distance we need to move before placing the next item

We make an actor BP. In that we have a map of the fixed buildings. It contains the slot they sit in and the mesh ( sprite )

We used a map, and not an array, because it’s really handy to lookup if that slot is used for a fixed item.

And an array or random elements

Then, the construction script is just

At each step, we figure out if we have a fixed item there, and take that spec. Or, we take a random street element, and use it’s spec.

Then add the necessary distance, and place the mesh ( in your case sprite ).

I’ve made the fixed buildings out of procedural grid material, to make them stand out

And this is it in action

street2

All things are possible with this general concept. Making the street a fixed length, putting it all on a spline, to go around corners. Fixed building always in the same place etc.

What I’m trying to get across is that if you have the right data structure and concept, you don’t need any hard coding.

1 Like

( I tweaked it again slightly. In fact, with the sprite spec, you have to store HALF the distance. Add it before dropping the sprite in, and then again afterwards. Then they all connect just fine. )

Oh wow, this is more then I expected, and I am really grateful, thank you so much. I’ll try and implement it now and see what happens.

1 Like

Tell me how it goes :slight_smile:

1 Like

This works a treat, thank you. Its so much cleaner then what I was attempting and has a good amount of user control.

1 Like

Great :slight_smile: