Cannot remove item from array from child BP

Hi,

I have an array of structs which is defined in my parent BP. When i try to remove an item from the child BP, the Remove node returns true, but on the next loop through the array, the item it still there.

Has anyone had a similar issue?

Thanks.

If there is no spawned instance of the parent then the values can’t be changed as nothing can change on something that doesn’t exist. You need to spawn the BP into the world and keep it there. Create a variable to hold that instance and manipulate the parent from that variable instance. Once you destroy that instance of the parent then those values will reset to default.

Hope this helps!

PS.
I also wanted to add that a parent should only have generic information for each child to inherit and have the child implement values to themselves. Placing hard coded values on a parent for each child to change probably isn’t the best solution or you may end up with undesirable results. For instance, say you have a health value on the parent which each child inherits. If you have the children change their own health on the parent then all children’s health will change to reflect the parent.

Thank you very much, jsmith. So how do I spawn a BP? It’s not a class, it’s a widget BP, so I just add it to viewport. Is there smth else I need to do?

With all my widgets, I usually spawn, or in widget terms “create” them when the game is first started. I have a function in my player controller (because it’s easy to access but game mode or game state would work for this as well) that I call at “Begin Play” which creates all my widgets and sets them to variables. Then, whenever I need access to that instance, if I’m not calling from my player controller, I get a reference to my player controller, set that to a variable and then I have access to every single widget I created from “Begin Play”.

Also, you don’t need to add your widget to viewport in order to have access to it’s instance. As long as it’s created and set as a persistent variable that you can easily retrieve from anywhere, you are good to alter it’s values.

Did that clarify it a little better for you?

Thank you, I have that (I create the parent widget at Begin Play, only don’t set it to a variable). The array can be seen and accessed from the child widget. Still can’t understand why the child cannot modify it :slight_smile:

Because you aren’t keeping the instance of the widget which means it’s values reset to default. You can not change the values of something which does not exist. The default values are always there - period. An instance of a blueprint is the only thing that can be changed at run time - children will * always * see their parent’s functions, values, variables, etc whether the parent is instantiated or not but you can’t change the values on something that does not exist within the game.

You can tell a dog to sit all day long but if he’s asleep he can’t hear you and therefore continues to lay down, which is the default behavior of a sleeping dog. Keep the widget instance in a variable, call the variable from the child, manipulate your data via that variable and voila!

jsmith, I understand it now :slight_smile: Thanks a million for helping me solve a problem I’ve been struggling with for 2 days.

You’re very welcome. I had a similar issue when trying to understand casting an object! If my answer helped, it would be great if you would accept the answer which in turn will make it easier for people to find in the future should they experience the same issue.

I accepted it :slight_smile:

Yet another question: I create my widget in the Level BP (at Event Begin Play), and it seems the variable it is set to cannot be accessed from another BP. What is the right approach to this?

Don’t store it in the Level BP because you can’t access the Level BP from anywhere else. For example, you can’t Cast to it and pull variables, values, functions, etc from it like you can other blueprints. I do all my BP references in my custom Player Controller because the player controller is easy to get from any other BP by Casting to it. Other good spots might be Game Mode or Game State though you should be careful of putting too much in those BP’s. Player Controller (a custom one) is probably the best place because it’s automatically instantiated when the game starts and stays persistent throughout the level (but changing levels during gameplay will reset and reload your controller.)

Also, to accept the answer you need to click the check mark that sits below the arrows next to the answer. When you accept it, the answer plus these comments will highlight green :slight_smile:

Hey jsmith,

Works perfect. Thanks for the help once again :slight_smile: