Blueprint value is not set?

I’m trying to make an RTS-style camera. I followed the Unreal tutorial C++ code on how to make a static camera with spring arm component(https://docs.unrealengine.com/en-us/Programming/Tutorials/PlayerCamera/1). It works, although I am still confused about spring arm component. I created a BP of my camera pawn and played around with the values to create the desired effect. It seems however, that some of the values exposed to the blueprint editable are not changed when I change them even though all of them have EditAnywhere UPROPERTY. For example, I was able to change the camera speed inside blueprint editor. I know this for sure because if I set speed to 0, camera wont move by my inputs. I am also able to change the cameraLagSpeed of spring arm component. However, some value dont work, for example the height of the camera from the ground.

When I changed spring arm component TargetArmLength like this:

cameraSpringArm->TargetArmLength = 1400.0f; 

Then I see the camera moves further from the ground, which is what I want. However, doing like this

cameraSpringArm->TargetArmLength = height;

with height set to 1400 from blueprint doesnt work.

Even weirder, when I tried to debug in visual studio, all the values, even speed and cameraLagSpeed (which work as expected) are 0. I am very new to Unreal, and don’t know where I am wrong at all.

sometimes if you change something in the c++ file and then compile unreal will swallow the number you set in the blueprint. if you want to be sure that unreal doesn’t do that, set the values of the variables in the header file.

Hi, @PasteteDoeniel, thank you for your answer. I think you misunderstood me. The height value is not set anywhere, but in blueprint.

I don’t think I misunderstood you. What I said was, that if you compile a c++ file, unreal has the tendency to forget the values you set in the blueprint, setting the values to 0. Which means you have to go back into the blueprint and set the values again.

@PasteteDoeniel I dont think that’s the case here since I checked the blueprint editor and the height was set to the value i wanted

ok hold on. you set the height value in blueprint and not in c++. How are you accessing that variable in c++?

UPROPERTY(EditAnywhere)
float height;

So I have it like this in my header file. In my .cpp file, I use it like this

cameraSpringArm->TargetArmLength = height;

And I set the value of the height in blueprint

ok this is what I meant with unreal forgetting values. to prevent that try the following:

UPROPERTY(EditAnywhere) float height = 1400.0f;

that way unreal won’t forget the value. Now if you edit value in blueprint again, it will accept that new number, but if unreal should forget the value again, it will now take the 1400 instead of 0.

I suspect you trying to do this in constructor or some early event, thing is this is normal C++ and there somethings that UE4 can not supervise and one of them is execution of constructor.

Constructor is executed right away when object is created, before UE4 can even touch it, because of that UE4 can not set blueprint defaults on to properties, in fact UE4 assumes that you will set default values and create copy of those in Class Default Object (CDO) and use them as defaults in blueprint. Ofcorse this creation limitation that you can not create default variables copies like you trying to do.

Toi get variables form blueprint you need to wait after the constructor, in fact UObjetc class provides event when all varables are properly set by UE4 in your object called PostInitProperties, this is earliest point where you can process blueprint set defaults

This makes so much sense. I have been wondering why I needed post initialization to add sound files to audio components.

However shouldn’t it work to initialize the “TargetArmLength” value in “Begin Play()” for the OP?

It works. Thank you so much!