Cycle through an Array showing just one actor at a time

Hi all!

I’ve been trying to set a BP cycling through an array of actors with tags, so it only shows one actor at a time but I’ve been struggling at the minute getting the logic right.

I used a multigate/flipflop but as you can see I need to press the F key twice to make the changes:

The BP:




Construction Script for Initial Visibility

Also, the plan is to add a simple animation (Int 1 scales down, Int 2 scales up) and also adding a widget as an option with two arrows to go forward and backward.

Any help for pointing me in the right direction is greatly appreciated!

2 Likes

This way is easier

hide

If you want to make them grow and shrink, then it’s much easier to make each one an instance of a blueprint, because you’ll be using a timeline, and managing multiple objects from one piece of code is not worth trying :slight_smile:

2 Likes

To do it with a blueprint, this is the construction

Event graph

and level BP ( basically what we had before )

TL

If you want them in a specific order, that’s also easier in BP, just give them an ID

which you can set in the level

and when you first make the array, sort them by ID :slight_smile:

1 Like

Thank you! I really appreciate your time and explaining in such detail simplifying the process.

My idea is to be a drag and drop blueprint, add options via struct, so I can swap as many items as desired, and I can assign a tag for items, so for example I’ve got Item 1 (eg. box) which will start the game as visible, then when player press F, it’ll hide and show the next item in the list (sphere) and also cycle through a widget window (using buttons) if desired. Its application is for archviz.

So my thinking is, each index in the Struct will be connected to the element index of the mesh or actor to cycle through the whole array. So the index 0 or first option in the struct will be all actors with index 0.

The struct:


The floating widget:

Your solution works great with the increment to cycle through the items but I need the first index to be visible at the start.


So I took the array index on the struct to hide all object unless is index 0:

But now I need to press F twice to hide the index 0 object and now it jumps to the last object or 3rd option (cone in this case).

In the widget side of things, I was thinking using this method which I use for a gallery:

Thank you once again for your support on this, my knowledge in BP is not that extensive and sometimes I get lost complicating a process.

Maybe you can explain what you want purely in archvis terms?

For example, to stand in the kitchen, and run through all the different hobs available. Or would you want to change all items in the kitchen on each key press, in a sort of ‘these all go together’ kind of way?

1 Like

For sure! Let’s say I’ve got 3 armchairs that I want to present the client, I place them in the living room and the first option is the one that fits best so it’s visible, but I want the client to be able to swap them pressing a key or with a button via widget.

I’ve done it before where I set the static meshes and also done it via tags and it worked like a charm but I’ve been always limited by the number of available interactions in the BP, so if I needed to present 10 armchairs, I’ll need to create a new BP that allows me to swap 10 static meshes.

What I’m trying to achieve with this BP is to present as many options as I need be either 2,3,4,5,10 and use it throughout the level, whether is a hob, a sofa, an entire bathroom, and each option is differentiated by a tag.

I hope it makes sense.

1 Like

Yes, so it’s a blueprint that can take an arbitrary list of meshes and move to the next one on command.

You would have one copy of it for a chair ( loaded with chair meshes ), another copy for lights ( loaded with light meshes ).

At the moment you’ve placed everything in the scene, which is confusing during the setup, and inefficient during runtime. Not very inefficient, but not a great way of doing it.

Shall I show you how to set this up? You only need one blueprint, all others are just copies of it, loaded with a certain list of meshes.

1 Like

Please do as I’m always happy to find more efficient ways to optimise the projects.

Because my background is with offline renders, my experience and knowledge in optimisation is short.

Thanks

1 Like

Ok. So the basic blueprint holds everything, except the meshes. It has an array, ready for the static meshes, and an index variable. By default, the first mesh is a cone, so we can see what we’re doing

This is the construction script

Place a copy in the level

So you can see the collision box ( orange lines ), and the default cone, because we haven’t set anything yet. So I’m going to do a chair, I set the meshes

See I set the default mesh to 1. You can choose the default, now there are some.

Dragging a fresh copy of the same blue into the level ( which starts again as a cone ), I can configure for tables

For interaction, you need a way of knowing which object you are near. I hate this method, but we will just get it working for now. Better ways of interacting, and widgets can come later

Then, all we need it the stuff to hang on F

And this is the basics

tablechair

You can make a widget appear over the object ( as part of the default blueprint ), that’s called a widget component. Or you can make a widget appear on the screen when you get near the object.

Also, long term, a line trace for interaction is better. This method has problems when the objects are very close.

1 Like

Man you’re truly a hero! It makes sense to me and I did use a similar method in the past but couldn’t figure out how to add more meshes and make them swap.

Just got one more question, is it possible for me to use this method and a struct with an array of meshes?

What I mean is, each index has an array of meshes, in archviz terms would be, the armchair 1 has a footstool and reading cushion, option 2 would be another armchair with a side table and a blanket, option 3 a bean bag only, option n a bookcase and so on.

It’s just to have more flexibility.

Totally, the line trace for interaction is waay better, I set it on my character with an interface and has been much much better than doing it via overlapping boxes.

1 Like

I would avoid using structs. You will probably end up with messy code, and if you nest things in structs ( like arrays of structs or structs with arrays in ), things also can get buggy.

What you could do, is have more than one array by default. So, the one we have now, and the ‘extra’ array. If there is a footstool with chair 2, then index 2 also has a mesh in the second array.

You would then need a third array to specify the relative offset of the secondary mesh.

An easier option is just pre-merge some mesh combinations you like. Then they just become another mesh.

1 Like

Interesting to know about structs, I’ll make sure not to depend on them.

I think just pre-merging the combinations will work best long term as it’ll take mere seconds to execute, don’t know why I didn’t think of it before :sweat_smile:

Thank you so much for your time and your help, I really appreciated, I’ll mark the previous message as the solution.

If there’s any way I can make a donation please do share it.

Cheers

1 Like

They way you’re using structs is fine, but they become very unwieldy once you start mixing them with arrays, or nesting them.

If you know someone who might like the game, you could recommend it maybe :smiley:

1 Like

Awesome! I’ll do for sure!

1 Like

Sorry to get to back to this.

Just trying to do the grow and shrink function work but can’t get my head around it :man_facepalming: is there any way to make it work with this code?

I loved that I was able to do a forward and backward interaction just by swapping the increment by a decrement, so now I can set the buttons in the widget:

568cc17c638deb0089bbeb1da6f9fdec

1 Like

With counting backwards, instead of setting the index to 0, you need to set it to LAST_INDEX

Do you want the shapes to swap sizes simultaneously?

1 Like

Yeah I forgot about the last index bit.

I was thinking of adding a delay in between just to give it time to one to shrink completely and then the other grows after the first one disappears.

What I did before is set it at the same time as per the timeline (0.5)

1 Like

This is where we are now

chair

( It’s a .5 sec TL )

1 Like

Man, I can’t thank you enough for your help and time on this, it’s working like a charm! :star_struck:

If you know of a course or books I can read to improve my knowledge in blueprints, because I wouldn’t have gotten to that point to be honest x)

I’ve got your game and this weekend I’ll try it out and recommend it to some friends whom enjoy logical games.

May god bless you and bring you lots of success.

Cheers

1 Like

Thank you :blush:

There is no book or course, unfortunately. It’s youtube ( sometimes very bad ) videos all the way. And a lot of mistakes :joy:

1 Like