I'm struggling making a door that opens up/down

I’ve been trying to set some floats and FVectors for a gate door and I’ve tried using the same code as in the door rotation, but I keep making Unreal crash, then rebuild everything, then fail again. It’s been a few good hours now and I’d like some help. So, if an FRotator holds the XYZ rotation coordinates, what holds the XYZ for the position/location?

The code I’ve tried that crashed Unreal several times was

float InitialLocation = GetOwner()->GetActorLocation();
UE_LOG(LogTemp, Error, TEXT("The object is at %f"), *InitialLocation)

Note: I’ve also tried %s or GetActorLocation().Z

When I try to compile it crashes. I don’t even know why. I tried deleting the component and made a new one in hopes it will work. When I try to initialise the float in the header float InitialLocation; at private, then add the code I wrote above it just crashes. I don’t even know what is happening. Can anyone point me into the right direction? Thanks!

FVector.

%f would be correct there.

That would mean you’re doing that in a constructor and the component doesn’t have an owner yet, That means you’re dereferencing a null pointer.

Thanks for your help, Dan. I did manage to get a little further in my code. I am printing a float 0.000 in the log, but I tought it would give me 3 values XYZ. I’ve initialised the FVector in the header as: FVector InitialPosition = FVector(0.f, 0.f,0.f); After that, in the cpp file I’ve put this
FVector InitialPosition = GetOwner()->GetActorLocation();
UE_LOG(LogTemp, Error, TEXT("Gate is at %f"), &InitialPosition.Z);
The log is printing:Annotation 2021-01-07 205736 , but the object’s coordinates are

Annotation 2021-01-07 205755

Am I doing something wrong? How could I get the return of GetActorLocation() as actual coordinates?

You’re only giving it a single value (Z). Like I said earlier, use ToString if you want to print the values of the FVector.

That is printing the address of InitialPosItion.Z though will the incorrect format specifier to print an address.

// Print Z axis value
UE_LOG(LogTemp, Error, TEXT("Gate is at %f"), InitialPosition.Z);
// Print all values
UE_LOG(LogTemp, Error, TEXT("Gate is at %s"), *InitialPosition.ToString());

Thank you, Dan. It took me almost 3 days and all I had done wrong was use an ‘&’ in the wrong place! I need to study pointers a lot more. Thank you very much!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms