Download

OnConstruction not working as expected in Viewport tab of Blueprint editor

I’ve got some OnConstruction() logic in an AActor subclass designed to assist in level editing, doing things like constraining items to axes. These things work great in the PIE viewport.

However, the game doesn’t use a static level, it procedurally generates the level from an array of “tiles” (the [FONT=Courier New]AActor). We’ve got a base C++ class that all of the tile Blueprints subclass. When modifying components of a subclass in the Blueprint Editor’s Viewport tab, the[FONT=Courier New] OnConstruction() function fires, but it doesn’t affect the world the way we’d expect.

For example:


void AEnvironmentStartTile::OnConstruction(const FTransform &Transform)
{
	Super::OnConstruction(Transform);
	
	FString Message = FString::Printf(TEXT("(%f, %f, %f"), ForegroundAttachPoint->RelativeLocation.X, ForegroundAttachPoint->RelativeLocation.Y, ForegroundAttachPoint->RelativeLocation.Z);
	GEngine->AddOnScreenDebugMessage(-1, 1.5f, FColor::Red, Message);

	ForegroundAttachPoint->RelativeLocation.Y = 100.f;

}

[FONT=Courier New]ForegroundAttachPoint is an arrow component, and if I drop an instance of this class into the world, it keeps the arrow at Y=100. In the Viewport tab of the Blueprint editor, I can see that [FONT=Courier New]OnConstruction() is getting called, thanks to the [FONT=Courier New]AddOnScreenDebugMessage() call, but it doesn’t work as expected. What it does is prevent any movement at all on any axis.

I’ve tried many variations, including using PostEditChangeProperty instead, and also subclassing UArrowComponent and overriding [FONT=Courier New]PostEditComponentMove. With everything I’ve tried, either nothing happens, or the wrong thing happens (all three axes constrained instead of just one).

Is there a way to do what I want to do - to enforce constraints on the person building the blueprint subclass rather than working with an instance in a map?

Any help is appreciated.