Description

When spawning a pawn that has a PawnMovementComponent attached and destroying the pawn, if a pawn with the same name is re-created it will be missing the PawnMovementComponent.

Steps to Reproduce
  1. Open UE4 Editor (code Third Person Template project)
  2. In Project Settings->Input, add Action Mapping for "Spawning" and "Removing"
  3. Add class to project based on pawn (MyPawn)
  4. Add class based on PawnMovementComponent (MyMovementComp)
  5. Add include statement for MyMovementComp to MyPawn.h
  6. Add the following to MyPawn.h:
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "OurPawn")
    	class UMyPawnMovementComponent* MyPawnMovementComponent;
    
  7. Add the following to the constructor of MyPawn.cpp:
    // Initialized in AOurPawn constructor:
    MyPawnMovementComponent = CreateDefaultSubobject<UMyPawnMovementComponent>(TEXT("MyPawnMovementComponent"));
    
  8. Add the following to ProjectNameCharacter.h:
    	void SpawnDummy();
    	void RemoveDummy();
    
    	AMyPawn* TempActor;
    
  9. In ProjectNameCharacer::SetupPlayerInputComponent add the following bindings:
    	InputComponent->BindAction("Spawning", IE_Pressed, this, &AMyProject7Character::SpawnDummy);
    	InputComponent->BindAction("Removing", IE_Pressed, this, &AMyProject7Character::RemoveDummy);
    
  10. Add the following to ProjectNameCharacer.cpp:
    void AMyProject7Character::SpawnDummy()
    {
    	FActorSpawnParameters SpawnParams;
    	SpawnParams.Name = "Pawn123";
    	SpawnParams.Owner = this;
    
    
    	FVector SpawnLocation;
    	FRotator SpawnRotation;
    	SpawnLocation.X = GetActorLocation().X;
    	SpawnLocation.Y = GetActorLocation().Y;
    	SpawnLocation.Z = GetActorLocation().Z;
    
    	SpawnRotation.Pitch = GetActorRotation().Pitch;
    	SpawnRotation.Roll = GetActorRotation().Roll;
    	SpawnRotation.Yaw = GetActorRotation().Yaw;
    
    	TempActor = GetWorld()->SpawnActor<AMyPawn>(AMyPawn::StaticClass(), SpawnLocation, SpawnRotation, SpawnParams);
    
    	
    }
    
    void AMyProject7Character::RemoveDummy()
    {
    	TempActor->Destroy();
    }
    
  11. Compile the code
  12. Play in the editor and call Spawning
    pressing Shift+F1 and selecting MyPawn in the world outliner will show the movement component in the details window
    
  13. Call Removing to destroy MyPawn and then call Spawning again

Result:
When Spawning is called the second time, the pawn is created but is missing the PawnMovementComponent

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-23291 in the post.

0
Login to Vote

Fixed
ComponentUE - Foundation - Core
Affects Versions4.9.24.10
Target Fix4.17
Fix Commit3528738
Main Commit3555226
Release Commit3528738
CreatedNov 12, 2015
ResolvedJul 10, 2017
UpdatedAug 10, 2017
View Jira Issue