I’ve been trying to figure out how to create a different static mesh for an actor depending on conditions it’s spawned in.
When I try to add a new static mesh to the Actor in a function that isn’t the constructor, the Engine crashes when the function is called.
Example of the function is below:
void AActor::BuildLeft(UStaticMeshComponent* Left) {
DummyRoot = CreateDefaultSubobject<USceneComponent>(TEXT("Dummy0"));
RootComponent = DummyRoot;
static FConstructorStatics ConstructorStatics;
Left->SetRelativeLocation(FVector(0.f, -75.f, 0.f));
LeftMesh->SetStaticMesh(ConstructorStatics.LineMesh.Get());
Left->SetRelativeRotation(FRotator(0.f, 0.f, 0.f));
Left->SetupAttachment(DummyRoot);
}
This is a second version of the function with me trying to pass a static mesh declared in the constructor, declaring the static mesh in the function and passing nothing also didn’t work.