Probably trivial problem with Do Once

I have encountered a behaviour with Do Once which I don’t understand and even though I can work around it, I would love to know what’s going on. Most probably it’s just me not understanding something really basic.

I have this setup:

  • character BP that has all the functionality
  • a child of the character BP that serves only to setup/overwrite specific variables
  • animation BP that is being used by that child character BP
  • from the animation BP I’m reading a value (“Trot2Run Threshold”) that is setup in the construction script of the original character BP (the parent), I’m doing this reading by casting from Anim BP to owning actor/character
  • I’m storing this value in another variable (“Trot2Run Threshold ABP”) inside of the animation BP

The problem:

  • if I store the variable via animation update event (every tick) all is fine
  • as soon as I try to store the value only once via Do Once, the value is set to zero (I tried to do this as some sort of optimization because the value isn’t changing over time so it should be enough to set it only once)

Picture for clarification:

&stc=1

The top version doesn’t work, always set’s "Trot2Run Treshold ABP to “0” (i guess it’s setting it specifically to 0 otherwise it would keep it’s fancy default value if it wouldn’t happen even once)
The bottom version works ok.

Would appreciate if someone could explain what I’m doing wrong or if I have wrong expectation of how this should work.

Thanks

Try adding delay of 1 second to do once setup.
This may be something that has some delay when its value is set.

Also run game for few seconds, print Trot2RunTreshhold there, and see if id does not have few zeros at beginning.

You can always modify “Set Trot2run…” node make it into macro with debug printing value when its set. Then print it all to log, you can see if it changes.

I doubt if this problem is cause by doonce, however i had similar problems with arrays, for them its better to save to variable, then get from variable, than to drag connection between far in execution parts of graph.

Hi Nawrot,

you were right, with a bit of fiddling with delays and log printing I have found out that in the first frame the value is really 0. So I guess all is working as it should.
This leads me to two questions:

  • Would it be better to just leave the value being setup every tick or is the trick with delay worth to use (e.g. it really saves something on performance)? Maybe there is a third solution?
  • So if the parent BP has some calculations setup in it’s construction script, the actual calculation happens in it’s child BP if that’s what I’m using for my character?

Thanks again.