Array not adding, but overwriting index

Hi all!

In my game, you can interact (I’m using component overlap to enable input + enhanced input system) with child BPs in the world to collect items, and those items should be added to their parent array, but it isn’t working.

The children “BP_Sigils_Child” (there’s 3 manually placed in the lvl) have a Name variable that’s editable and transfers it to a parent variable, nothing fancy.

The parent BP is called “BP_MasterSigils” and does all the work.

I’m having a problem with adding these child BP upon interaction. A custom event adds the name to the array…

And the interaction calls it to be added.

However, clicking the child BPs returns their names, but always with zero index. This is me clicking on one BP after the other and getting the same result.

imageimageimage

image

image

I’ve tried using ADD UNIQUE, doesn’t work. INSERT doesn’t even show any result. I’m not setting the array anywhere else, and it’s empty by default, since the plan is to add items at runtime. Both BPs start with tick enabled.

I don’t know if it’s a bug or just I’m not seeing what’s wrong : /

show the code for the print please.

how do you get the index?

i think something’s odd about that code.

also that doOnce is odd, with that DoOnce you will only be able to add one name at all.

do you have mulitple bps? if so, they have different variables. hence you’re adding to different places.

i don’t think you need the do_once. i think you need to configure your input action or context appropriately.

1 Like

how do you get the index?

I was transferring the array to my Game Mode for testing, just to see if my parent BP was the problem. The event below is being called on begin play by a Set Timer by Function Name node.

I have a similar setup in the parent BP, but the result is the same.

Prints empty 3x (the number of BPs in the level):

image

Interacted w/ BPs consecutively:

imageimageimage

also that doOnce is odd, with that DoOnce you will only be able to add one name at all.

I’ve added to prevent collecting the same BP after interacting with it. If I delete it, I collect the same one multiple times.

do you have mulitple bps? if so, they have different variables. hence you’re adding to different places.

I have created the parent and only 1 child. In the level, I’ve copied this child and pasted 3x and named them differently.

i don’t think you need the do_once. i think you need to configure your input action or context appropriately.

I do have a boolean to check when the BP is interacted, maybe that can be worked out in the input code?

Try making other variable arrays that adding to the same function and print the index.(some Name, String, Int array for measurement.)
If other array type’s index prints fine(not 0), you may have to clean/rebuild your project(delete Binaries folder to regenerate blueprint codes).
And if other array type’s index is also 0, then I donno :face_with_diagonal_mouth:

I’ve created another array and deleted the project folders, got the same result. I was testing sending the array content to a Game Mode array, but yeah, nothing changed.

The only thing I fixed was deleting the Do Once node and adding a branch check in the interaction code, and now I can click LMB multiple times and the items stops being added to the array. But the index doesn’t change, it keeps the name at 0.

Hey @BrainMayhem!

Just something really fast- a big piece of information that I’m not seeing.

When you GET that Array, are you getting a REF or a COPY?
Ref(erence) will get you the actual, original, permanently changeable array- I’m seeing a lot of Copy behavior- not saving permanently etc. Copy is great for when you need a starting off point over and over for math functions and such.

Sometimes the biggest problems are due to the smallest details, you know? :slight_smile:

Sometimes the biggest problems are due to the smallest details, you know? :slight_smile:

Oh don’t we know that hahaha

Well, the only place that I was using GET was to read the array, and it was indeed getting a copy not a ref. I’ve replaced the node, but I’m getting the same result.

image

Zero index.

–––––

Tried another logic and still zeroing.

Does adding to arrays have any secrets or settings that I’m not doing beforehand, or any extra configuration regarding the relationship between parent/child? Should I call a priest to exorcize my project?

I think this is the problem. Each child has its own array of names and the master blueprint doesn’t work like you intend it to. To use a master blueprint you would need to drag it into the level or something and create a direct reference to it so that you could call an event to it, otherwise you are just interacting with 3 different master blueprints.

2 Likes

Yeah, that seems to be the issue. I’ve given up using the Name variable, and I’m now trying to find alternatives for what I’m trying to do.
Thanks for the help everyone, if I ever find a solution, I’ll post here :slight_smile:

So I ended up doing a combination of parent BP + structs + various child BPs and now everything works as I planned!

1 Like