Keeping STRUCT synced during play when used in multiple BP:s?

Hi,

I’m having a bit of trouble dealing with STRUCTS. I’ve started a new project from the SideScroller template to make things easy to demonstrate my question/problem.

While playing I want to change the struct values depending on that I do. In this case walking over an actor and trigger a FlipFlop on a boolean struct value (unlocking/locking a weapon).


I have two structs:

  • struct_weapons - the parent, setting default values of the weapon here (changes of Set member-node should be committed here)
  • struct_weapons_params - the child, only defining the parameters

And I have an Actor named trigger_unlocked that will trigger on Overlap, does a FlipFlop on the unlocked boolean I have in the struct_weapons struct. I’m using Set members-node to change the value (I have a variable called lib_weapons that type is struct_weapons.)

Now in my SideScrollerCharacter I have setup a basic input key E - to print the status of struct_weapons weapon. (Here I also have a variable called lib_weapons that type is struct_weapons.(


I play the game, press E and it prints the default value of lib_weapons: unlocked: false. When I move over the trigger actor it prints unlocked: true. But when I press the E key again it still prints unlocked: false (when it should be unlocked: true).

Am I missing something? I thought Set members-node should update the struct but it doesn’t.

I’ve added an album explaining everything in more detail: http://imgur.com/a/xJ7Z9#0


Character

actor overlap trigger

struct_weapons

struct_weapons_params

trigger actor activated and pressed E key to print unlocked status

I’m not certain that I got the gist of it but is it possible that your problem is due to you using a cast node but not dragging a pin off it to set your structures?

Your problem is that you are never actually setting the struct within the character’s blueprint. The Lib_Weapons you change in your trigger blueprint is a different struct from your character blueprint’s. Struct variables are just like any other variable, variables in different classes are not linked in any way. You have to call the variable in the Character’s BP if you want to change that value.

In order to change the character’s lib_weapons value you need to drag off of the As Side Scroller Character in your trigger_unlocked event graph and use the Get Lib Weapons node. From there you can use that, instead of the lib_weapons, in your trigger.

Well now I feel stupid, I forgot the most basic thing about variables. I was thinking structs worked differently because it’s a separate file and that I could do operations on that file.

Thanks, I got it working now!