Calling SetConstraintMode on Actor causes editor to crash

When I’m calling SetConstraintMode(EDOFMode::XZPlane); in an actor’s constructor, the editor crashes with EXCEPTION_ACCESS_VIOLATION. The editor always says it crashes on line 20, which is when I set the root component to be the Sprite, however, commenting out SetConstraintMode stops the editor from crashing. My code is as follows:

    Sprite = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("Sprite"));
	Sprite->SetSimulatePhysics(true);
	Sprite->SetEnableGravity(true);
	Sprite->SetConstraintMode(EDOFMode::XZPlane);
	SetRootComponent(Sprite);

edit: It stopped the editor crashing until BeginPlay() was called. The actor that is using SetConstraintMode() is being spawned so now it crashes the editor when the actor is spawned… I’m just going to make a blueprint from the c++ class and edit the constraints from there I think.

What if you SetConstraintMode() under BeginPlay(), and not in the constructor?

I’ve encountered various functions that don’t work well in the constructor, but fine on BeginPlay(). Maybe this is one of them too?

1 Like

lets see how did you declare your Sprite, can you share your .h file as well?
if you declared it like this you shouldn’t have problem

UPaperSpriteComponent* PaperSprite;

Yeahhh it’s pretty much just that -

	UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category="Sprites")
	UPaperSpriteComponent* Sprite;

Test in UE5.0.0, Put it in BeginPlay() solved my problem!

I still have the same problem. Put in BeginPlay doesn’t solve this problem. Any one can help me?
I’m using unreal engine 5

1 Like