C++ SetActorLocation Is Not Working Here

Hello! So, this is strange behavior, and I’m stumped why this is happening.

I have a pointer to an actor in the scene, and this actor is a blueprint, derived form a C++ class (and it should be noted that in the scene, this actor is attached to another actor but I am not moving that one), and this class has no code in it, other than variables. A scene root, and a skeletal mesh attached to it.

My player class has a the reference to that actor in the scene. When I run the game in Play in Editor or Standalone, I try to move the actor reference with SetActorLocation. Here’s the strange part, it doesn’t move. I’ve verified in the Inspector that the player vairable reference to the actor is set correctly, and it doesn’t move, however, if I left click on that actor in the inspector, then click back into the Play In Editor, it moves, and functions normally.

Here is the code that functions here:

Player_Edit.cpp:

void APlayer_Edit::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	if (PController != NULL && SelectedPart != NULL && IsDragging)
	{
		FVector wLoc;
		FVector wDir;
		PController->DeprojectMousePositionToWorld(wLoc, wDir);

		FVector start = wLoc;
		FVector end = start + (wDir * PartDistance);

		end = end.GridSnap(GridSnap);

		SelectedPart->SetActorLocation(end);
	}
}

I’ve made sure that the variable IsDragging is in fact true, and both the controller and selectedpart variable are correct when in game, but it only allows me to drag the actor around if I left click it in the inspector first.

Any ideas why this is happening? Thanks in advance!

2 Likes

Solved it. I made the skeletal mesh the root of my actor! Spent hours on this haha, glad I figured it out! Hope this helps someone else if they have a similar problem.

3 Likes