Download

why AActor::SetActorLocation not work ?

Hi all, I had build a MatineeActor animation, which binded a airplane(static mesh actor). sometimes i need another airplane follow the matineeActor animation, I write c++ code like this:



		AActor* tempActor = PlayerController->PlayerCameraManager->GetViewTarget();
		if (tempActor)
		{
			FRotator rotator = tempActor->GetActorRotation();

			const FQuat RelativeRotQuat = rotator.Quaternion();
			const FQuat DeltaRotQuat = rot.Quaternion();
			const FQuat NewRelRotQuat = RelativeRotQuat * DeltaRotQuat;
			tempActor->SetActorRotation(NewRelRotQuat.Rotator());

			TActorIterator<AStaticMeshActor> ActorItr = TActorIterator< AStaticMeshActor >(GetWorld());
			while (ActorItr)
			{
				FString name = ActorItr->GetName();
				if (name == "SM_Hang_Glider_2" || name == "SM_Hang_Glider_4")
				{
					OutputDebugString(*name);
					ActorItr->SetActorRotation(rotator);
					FVector location = tempActor->GetActorLocation();
					ActorItr->SetActorLocation(location, true);
					OutputDebugString(*location.ToString());
				}
				++ActorItr;
			}
		}


“tempActor” is the airplane binding on matineeactor, “SM_Hang_Glider_2” is another airplane’s name in editor, and “SM_Hang_Glider_4” is ID NAME of the airplane(i don’t know why the name and the ID NAME not the same, and i don’t know which i need to use, so i write a “or” Expression).
In my code, i found the “SetActorLocation” don’t work? i can not get what i need. The second airplane could not see while i play the matinee animation. how i can deal with this? this code is run on actor tick event. and the “tempActor” 's location output is corret.
thankyou a lot!
sorry for my poor english.

Getting the Actor by name probably isn’t a great idea, the ID names can vary depending on the order in which things are Spawned, how many times you run in PIE etc.

You’d be better off storing a direct pointer to the actor somewhere and doing it that way.

Thanks for your reply.“Getting the Actor by name probably isn’t a great idea”, thanks for your Suggestions, i agree. i just do a test for the set actorlocation. I had done this on level blueprint. it also not work. I had set the first actor “always hideden in the game”, may be is the reason? or may be because the first actor attach to a matinee animation?i need your help. thankyou.
sorry for my poor english.

Hope it will not cause PIE memory leaks.

It’s not that, it’s that everytime you do PIE, it increments the number of the actor at the end, so you can only run the above code in one session before you have to close and open the editor.