SetSimulatePhysics(true) - object dissapears

Hello!

I’m creating new paperspritecomponent and want it to just fall down to see if physics will start to work on this component. However it seems I am not able to use physics on this component as it just dissapears after that.

Here’s my setup:

void ALadder::BeginPlay()
{
	Super::BeginPlay();

	if (LadderLinkSprite && LadderEndSprite && LadderAnchorSprite)
	{
		UPaperSpriteComponent* NewLink = NewObject<UPaperSpriteComponent>(this, *FString("AnchorLink"));
		NewLink->RegisterComponent();
		NewLink->SetSprite(LadderLinkSprite);
		NewLink->SetWorldLocation(FVector(-34300.0, -290.0, 1250.0));
		LadderLinks.Push(NewLink);
		NewLink->SetMobility(EComponentMobility::Movable);
		//NewLink->SetSimulatePhysics(true); --> // this line hides my new paperspritecomponent for no reason
	}
}

One reason why physics did not work on paperspritecomponent was because its sprite had no collision set. When I added a simple collision box around my sprite, it just disappeared. I have no clue why it’s happening.


I tried to reproduce the issue by creating a simple actor with the following code and it’s not working when done using the following class.

Myactor.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"

UCLASS()
class GAME_API AMyActor : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AMyActor();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(EditAnywhere, Category = LadderControls)
		class UPaperSprite* LadderLinkSprite;
	
	
};

MyActor.cpp
// Fill out your copyright notice in the Description page of Project Settings.

#include "MyActor.h"
#include "PaperSprite.h"
#include "PaperSpriteComponent.h"

// Sets default values
AMyActor::AMyActor()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
	Super::BeginPlay();

	if (LadderLinkSprite)
	{
		UPaperSpriteComponent* NewLink = NewObject<UPaperSpriteComponent>(this, *FString("AnchorLink"));
		NewLink->RegisterComponent();
		NewLink->SetSprite(LadderLinkSprite);
		NewLink->SetWorldLocation(FVector(-33500.0, -290.0, 1250.0));
		NewLink->SetMobility(EComponentMobility::Movable);

	}
	
}

// Called every frame
void AMyActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

Waiting for your response
With regards

After setting the world location of the created component after calling SetSimulatePhysics(true) function, the problem was solved, but I’m still wondering why the problem happened.

Traced the SetSimulatePhysics(bool bSimulate) function call;

void UPrimitiveComponent::SetSimulatePhysics(bool bSimulate)
{
	/*----------------------> */ BodyInstance.SetInstanceSimulatePhysics(bSimulate);
}

void FBodyInstance::SetInstanceSimulatePhysics(bool bSimulate, bool bMaintainPhysicsBlending)
{
	if (bSimulate)
	{
		UPrimitiveComponent* OwnerComponentInst = OwnerComponent.Get();

            ...
            ...

		if (OwnerComponentInst && OwnerComponentInst->IsRegistered() && OwnerComponentInst->GetBodyInstance() == this)
		{
			if (OwnerComponentInst->GetAttachParent())
			{
				OwnerComponentInst->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
			}
			
			if (bSimulatePhysics == false)	//if we're switching from kinematic to simulated
			{
				/* ---------------------------------> */ ApplyWeldOnChildren();
			}
		}
	}

	bSimulatePhysics = bSimulate;
	if ( !bMaintainPhysicsBlending )
	{
		if (bSimulatePhysics)
		{
			/* ---------------------------------> */ PhysicsBlendWeight = 1.f;
		}
		else
		{
			PhysicsBlendWeight = 0.f;
		}
	}

	/* ---------------------------------> */ UpdateInstanceSimulatePhysics();
}