Make sure your C++ values don't overwrite your Unreal Engine values

I don’t know who needs to hear this but if you got puzzled midway through this lecture and wondered why all of a sudden your cubes went from moving up and down to slowly moving left and right, I found the problem. With EditAnywhere, you can set your variables both within C++ and Unreal Engine at the same time but if you set your variable values in C++ and then compile, your Unreal Engine variable values will be lost and it will use the C++ values.

So here’s my suggestion:

  1. Set your variable values in C++ if you want consistent behavior with your cube movement, for example: If you want all cubes to be moving in one direction and the same speed.
  2. Set your variable values in Unreal Engine if you want different speeds and directions of movement per cube.

So for #2, set your C++ variables as follows:


If you want to keep the C++ variables, just remove the comment lines ( // ) and set your values appropriately.

Edit: If you have any problems with it saving the values in Unreal Editor, make sure you go back and review this video: Live Coding Issues | GameDev.tv
To avoid that problem, try running a Run Build Task when making changes to the C++ header file (the .h file),

I don’t think the C++ code can override values from the Unreal Editor, not via the field definitions at least (it obviously can from the function while running the game).

Variables always have a value anyway, either set explicitly by your code, or implicitly though other mechanism (constructors, compiler, remnant value from whatever was at that memory location before, …). UE has no way to know if a variable was initialized or not (well, at least I don’t think it does, with an appropriate framework it’s possible, this kind of tracking is usually too expensive in CPU or RAM). So not assigning a value shouldn’t fix your problem.

More likely, you problem stemmed from the same or similar issue mentioned in your edit and the “Live Coding Issues” video: not recompiling your project with the Build Task when restarting UE.
Or maybe you did something that caused UE to lose track of your variables, e.g. renaming them.

Privacy & Terms