x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.8
Tags:
more ▼

asked Jul 31 '15 at 11:08 AM in Blueprint Scripting

avatar image

locus_80
15 3 4 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jul 31 '15 at 11:49 AM

avatar image

jtsmith
1.4k 70 29 92

avatar image locus_80 Aug 01 '15 at 04:47 AM

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?

avatar image jtsmith Aug 01 '15 at 05:57 AM

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?

avatar image locus_80 Aug 01 '15 at 06:50 AM

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 :)

avatar image jtsmith Aug 01 '15 at 07:12 AM

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!

avatar image locus_80 Aug 01 '15 at 07:16 AM

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

avatar image jtsmith Aug 01 '15 at 07:19 AM

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.

avatar image locus_80 Aug 01 '15 at 06:44 PM

I accepted it :)

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?

avatar image jtsmith Aug 01 '15 at 09:06 PM

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 :)

avatar image locus_80 Aug 02 '15 at 04:30 AM

Hey jsmith,

Works perfect. Thanks for the help once again :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question