Page 1 of 1

// Function called every time the Transform of object changes in editor. void UVectorSceneComponent::OnUpdateTransform(E

Posted: Sun May 15, 2022 1:43 pm
by answerhappygod
Function Called Every Time The Transform Of Object Changes In Editor Void Uvectorscenecomponent Onupdatetransform E 1
Function Called Every Time The Transform Of Object Changes In Editor Void Uvectorscenecomponent Onupdatetransform E 1 (223.69 KiB) Viewed 63 times
// Function called every time the Transform of object changes in editor. void UVectorSceneComponent::OnUpdateTransform(EUpdateTransformFlags UpdateTransformFlags, ETelepo rtType Teleport) { Super::OnUpdateTransform(UpdateTransformFlags, Teleport); // ... // Get the global) location of the component in 3D Space TArray locations; auto location = GetComponentLocation(); locations.Add(location); // Get the "parent" of this scene component. If the scene component is actor root - the "parent" // is the attached parent actor. auto* parent = GetOwner(); if (parent->GetRootComponent() == this) { parent = parent->GetAttachParentActor(); } // If there is a parent (i.e. the scene component is not root for owner OR the owner acto r has a parent actor) if (parent != nullptr) { // Do the same check for grandparent - in this case, it's always the parent's att ached parent actor auto* grandparent = parent->GetAttachParentActor(); if (grandparent != nullptr) { auto intermediateLocation = grandparent->GetActorTransform(). Inverse().Tr ansformPosition(location); locations.Add(intermediateLocation); } auto localLocation = parent->GetActor Transform().Inverse(). TransformPosition(loca tion); locations.Add(localLocation); // ... } // } As we saw in class - this code works as expected and correctly displays up to 3 sets of coordinates for the point. This snippet is seen twice in the code above: component- >GetActor Transform(). Inverse(). TransformPosition(location). Explain what it does and what its purpose in the code is. Here's the full class for reference.