I am using the code below, but when I press the button, the elevator doesn’t rise from its current position; instead, it goes to the origin. I checked the debug information, and the value assigned by this code is (0, 0, 0). Is there any way to make it rise from its current position instead of the origin?
Well assuming that i know nothing about code you could set the blueprint itself to (0.0.0) and then build the asset in world space. I do wish you the best of luck.
In the blueprint, it’s set to (0, 0, 0), but during code initialization, it defaults to the origin. CurrentLocation is initialized here to record the object’s initial position, which will change later as the object moves. At this point, it is only used to record the starting position. YuanLocation is used to store the original position, and TargetLocation is used to store the target position. The issue seems to lie with the GetRootComponent()->GetComponentLocation() code, but I can’t find the exact reason.
Problem solved: The reason might be the timing of the class creation. The breakpoint was triggered as soon as UE started, which made me realize that the value might have been assigned before this point. So, I moved it to BeginPlay, and it was successfully assigned.