Can't respawn an actor after destroying it from array

I’m working on an ability to select multiple walls in a scene and change their colour. When I select the walls with a Line Trace By Channel, I spawn a paint brush blueprint actor in front of each wall to indicate which wall is selected. I add some of the out hits from the trace, and this paint brush blueprint to a structure array.

Once I’ve confirmed the colour change I then use Destroy Actor to remove the paint brush blueprint actors from the array and then ‘Clear’ my arrays.

This works, but then if I go to select the walls again, the paint brush actor does not re-spawn, and the arrays must be messed up as I can’t then change the colour of any of the walls.

From trying to research what could be the problem, it’s probably because I’m looping through the array to destroy actors, which is then messing up the array somehow. But even when I just ‘Clear’ the array without looping through it or destroying actors, it still messes up the array as none of the other selection functionality works and I can’t change the colour of the walls.

Any help would be appreciated!

That CLEAR call at the end is clearing your entire array. Presumably, you only want to remove some elements?

To do this, you need to loop over the array backwards and use REMOVEINDEX.

I do want to remove all the elements I’ve added to the arrays, but it seems to almost destroy the array where I can’t add those elements back if I wanted to

CLEAR does totally empty the array. It holds nothing ( has no indexes ).

So I should be able to add things back into the array then right? Because I cant right now

Yes, after clearing the array, it’s just an empty array, you can start from scratch.

But it doesn’t let me add back those two walls to change their colour again. Is it something wrong with my other scripting in the pics I attached?
Thanks for the help!

You didn’t paste the code for filling the array.

I see you adding paint brushes, but not the walls.

Gotchya, so here is the colour changing process;

The above picture is the meat of the function that I have on the Player Character (Director Character).

  1. I set up an Input that is Left Mouse Click + Alt key. That fires this Function that starts with a Line Trace By Channel, then I set the Hit Actor, Component and Face Index.

  1. Checking if I hit the Wall itself or the Trim on the Wall

  1. I then Spawn the Paint Brush Icon Blueprint Actor and set it’s location to the Socket on the mesh of the Wall.

I also store the Hits and the Paint Brush into this Structure Array (I created it as a blueprint in the content drawer)

The ‘Paint Hit Actor’ is a Wall in this case.

  1. Once I release the ‘Alt Key’ it then creates a Dynamic Material for the Hit Actor (The Wall) and store the Matt into another Structure Array (if I select more than one wall). I also store it’s default colour in the array in case I want to cancel it.

Once that loop is done I toggle on the Colour Picker UI HUD/Widget.

Now I’m in a Function that’s part of the Colour Picker UI Widget, where I set the new colour from the colour wheel and apply it to all selected actors.

In the Event Graph of the Colour Picker HUD Widget;

Clicking the ‘Confrim’ button confirms the colour change, or if I Click the ‘Cancel’ button it reverts back to the default turns the HUD off.

Both end in calling the custom event that I have in the Event Graph of the Player Character (Director Character) - 'Reset Selected Paintables

And here is that custom event on the Player Character;

I’ve spent some time looking at this, and can’t see anything glaring.

Some things I find a bit confusing are ( maybe this will put you onto something ):

Surely this sets all colors to the same thing?

And, again, the reset selected paintables, seems to just throw everything away. Surely you only want to bin the most recent edit attempt?

You’re saying you can’t spawn paintbrushes any more after this clear? Maybe focus in that area. Draw a debug sphere at the trace point, put some print statements in, what is actually happening at that point? Because a cleared array can always take new input.

Sorry to not be more help.

Yes, applies the same colour to the selected walls - like in a house, you’ll likely have at least one side of the room the same colour if not the whole room, but being a film set you may want to do more ‘arty’ things too.

Ya, I got to keep debugging things here the best I can

1 Like

I’ve finally figured out what I did wrong here. In ‘2. Checking if Wall or Trim’ I do a ‘Switch on String’ based on the Material name.

Then in ‘4. Storing Paintable Material and Default Colour’ I Create a Dynamic Material Instance, but leave the ‘Optional Name’ field blank.

By leaving it blank the material will no longer have the two options I check for (M_Paint_Wall or M_Paint_Trim).

So it was an easy fix, I just set the name of the Dynamic Material based on which Switch route I take.

I also redid this whole function to simplify it.

1 Like