4.7 resets transformations and crashes when I want to correct them

I first encountered this problem with the first preview, thinking it was a temporary thing, but as it is still in preview 5 here is my report. I have some actors that use the construction script of the blueprint to dynamically add components. In 4.7 most of them lost their transformation (they are all at 0,0,0 now) as well as having the components weirdly arranged. I can delete them, but whenever I want to move them or create new ones and move them the editor crashes.

This is how it should look:

But this is how it looks and the missing components are now all in the world’s origin:

And here is the callstack from the crash:
[callstack.txt][3]

greetings,
FTC

Hi FTC,

I haven’t been able to repro this in-house. Could you post some screenshots of how you are creating the components or a link to download a test project that shows this problem in action? You can sent it by private message directly to me on the Forums.

https://forums.unrealengine.com/

(I wanted to comment, but it would not let me, so I posted this as an answer)

Sorry, my bad I have investigated further and it wasn’t actually the blueprint’s fault. I call a native c++ method from the construction script to create additional components and it seems the error results from a change on how the components are handled?

This is my old (4.4 - 4.6) code:

UArrowComponent* CreateArrow(const FVector& WorldSource, const FVector& WorldTarget, AActor* ArrowBase)
{
	UArrowComponent* NewArrow = NewObject<UArrowComponent>(ArrowBase);
	
	NewArrow->ArrowSize = 1;
	NewArrow->SetRelativeScale3D(FVector((FVector::Dist(WorldSource, WorldTarget) / 80.0f), 1, 1));
	NewArrow->SetWorldRotation((WorldTarget - WorldSource).Rotation());
	NewArrow->SetWorldLocation(WorldSource);
	NewArrow->OnComponentCreated();
	NewArrow->RegisterComponent();
	NewArrow->AttachTo(ArrowBase->GetRootComponent());
	
	return NewArrow;
}

and after a bit of trial and error I got this running:

UArrowComponent* CreateArrow(const FVector& WorldSource, const FVector& WorldTarget, AActor* ArrowBase)
{
	auto NewArrow = NewObject<UArrowComponent>(ArrowBase);
	NewArrow->CreationMethod = EComponentCreationMethod::ConstructionScript;
	
	NewArrow->RegisterComponent();
	NewArrow->ArrowSize = 1;
	NewArrow->SetRelativeScale3D(FVector((FVector::Dist(WorldSource, WorldTarget) / 80.0f), 1, 1));
	NewArrow->SetWorldRotation((WorldTarget - WorldSource).Rotation());
	NewArrow->SetWorldLocation(WorldSource);
	NewArrow->AttachTo(ArrowBase->GetRootComponent(), NAME_None, EAttachLocation::KeepWorldPosition);
	
	return NewArrow;
}

Note that I have removed all null checks for the sake of simplicity. I also am not fully sure whether or not I am actually handling the construction correctly.

Besides removing the manual OnComponentCreated call I added manually setting the creation method attribute. Not setting this seems to cause the crash.

Again I don’t fully grasp if this is how components should be instanced from the construction script, so any help is appreciated.

greetings,
FTC

That looks more or less right.

You need to also be adding your Component to the Actor’s BlueprintCreatedComponents array.

In general I would avoid calling RegisterComponent until you’ve done the rest of the set up, but it isn’t critical.

In Preview 6 you’ll need to change the CreationMethod to ::UserConstructionScript as I differentiated between components that came from the SimpleConstructionScript (the component tree in the Blueprint) and those that come from the UserConstructionScript (AddComponent calls in the blueprint graph).

One thing you could do to manage some of this for you (and be correct when I change things again…) would be to use AActor::CreateComponentFromTemplate instead of doing the NewObject yourself. As your template, I guess you would pass in UArrowComponent::StaticClass()->GetDefaultObject()

Thank you very much.

It appears that everything works now that I changed the way I construct the components, so this was not really a bug after all, just using the api wrong.

greetings,

FTC