Used GetActorLocation

So my conclusion for this project was to use the FVector function GetActorLocation.

Very similar to Ben’s but also a little shorter to write initially.
Also its a FVector not an FTransform.

FString ObjectPos = GetOwner()->GetActorLocation().ToString();

I can see the differences in that a Transform also has rotate and scale in it and that in order to calll these I would need a separate function GetActorRotation or GetActorScale.

So I can see some differences but the reporting for this so far is the same.

I don’t see many issues besides keeping that in my head and knowing the differences for now.

2 Likes

I did the same thing :slight_smile:

same here

FString ObjectPosition = “”;
FString ObjectName = “”;
ObjectPosition = GetOwner()->GetActorLocation().ToString();
ObjectName = GetOwner()->GetName();

I am a complete newb at c++ and gaming in general though I normally skip even coming on here but figured i would see what other people found

I did something much more complex:

       // ...
	AActor* Owner = GetOwner();
	FString ObjectName = Owner->GetName();
	FVector Location = Owner->GetActorLocation();
	FString ObjectPos = (
		"X: " + std::to_string(Location.X) + ", " +
		"Y: " + std::to_string(Location.Y) + ", " +
		"Z: " + std::to_string(Location.Z)
		).c_str();
      // ...

A little silly, though, considering all I had to do was call ToString on the location FVector (lol)!

Found the call to c_str() searching around the web (converts an std::string to a ‘C-String’ (array of char) (@see http://www.cplusplus.com/reference/string/string/c_str/ and/or https://www.tutorialspoint.com/cprogramming/c_strings.htm).

I did the same, and was wondering if there was a reason Ben didn’t choose it.

I just ignored the Rotation and Scale - just wondering if GetActorLocation() is marginally slower because of the extra two bits of data!

Privacy & Terms