Download

Adding components at runtime

For the life of me I can’t seem to get this to work. It just won’t show as a component.


UPaperFlipbookComponent* ASwatterActor::AddFlipbook(FString Name, UPaperFlipbook* Flipbook)
{
	UPaperFlipbookComponent* NewFlipbook = NewObject<UPaperFlipbookComponent>(UPaperFlipbookComponent::StaticClass());
	NewFlipbook->RegisterComponent();

	if(Flipbook != nullptr)
	{
		NewFlipbook->SetFlipbook(Flipbook);
	}

	NewFlipbook->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);

	return CurrentFlipbooks.Add(Name, NewFlipbook); //Just adds to a TMap
}

I’ve tried registering after the attach to no avail. I’m not sure what I’m doing wrong. Version 4.12.

Nevermind, just realized it should of been


UPaperFlipbookComponent* NewFlipbook = NewObject<UPaperFlipbookComponent>(this);