Announcement

Collapse
No announcement yet.

Adding components at runtime

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    Code:
    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.

    #2
    Nevermind, just realized it should of been

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

    Comment

    Working...
    X