[4.9] Did UE4 4.9 Break or change the way you attach and spawn objects?

It worked fully in UE 4.8.3 without any issues whatsoever or warning.

But i do get this warning when i pickup the weapon

LogActor:Warning: Weapon_AR20BP_C /Game/Maps/Prologue_00/UEDPIE_0_TestMap.TestMap:PersistentLevel.Weapon_AR20BP_C_1 has natively added scene component(s), but none of them were set as the actor’s RootComponent - picking one arbitrarily



Create Weapon Function


UWorld* const World = GetWorld();
	if (World)
	{

		FActorSpawnParameters SpawnInfo;
		SpawnInfo.Owner = this;
		SpawnInfo.Instigator = this;
		SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;



		if (SlotNum == 0)
		{
			Slot1Active = true;
			GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("WeaponPoint"));
		NewWeapon = World->SpawnActor<AWeapon>(Weapon->GetClass(), GetMesh()->GetSocketLocation(TEXT("WeaponPoint")), GetMesh()->GetSocketRotation(TEXT("WeaponPoint")), SpawnInfo);
		NewWeapon->CollisionComp->SetSimulatePhysics(false); 
		NewWeapon->AttachRootComponentTo(GetMesh(), "WeaponPoint", EAttachLocation::SnapToTarget);
		NewWeapon->CurrentPosistionOnCharacter = 0;
		//NewWeapon->CollisionComp->SetRelativeLocationAndRotation(FVector::ZeroVector, FRotator::ZeroRotator);
		}

[video]https://i.gyazo.com/c2f2a77cb2256b6c4077daca2d242ec4.mp4[/video]

I’m having the exact same problem. No idea what’s going on.

at least im not alone… Can we get some confirmation from some more users in-the community or Epic this is an official bug or was something changed and just poorly documented? Ive spent the last 2 hours reading the change-notes and i cant find anything they added or fixed that would affect this unless they omitted to not mentioning this in it. Which makes me a sad panda…

In constructor of your AWeapon, add something like:


RootComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("Root"));

Or, if you already have suitable component, just assign it, eg:


RootComponent = SolidMesh;

I am having a similar issue in blueprints, my bullets spawn in an offset location from the gun barrel since upgrading to 4.9

Here’s some info in the release notes about actor spawning. This might help.

Like this?




// Sets default values
AWeapon::AWeapon()
{

	// Property initialization
	CollisionComp = CreateDefaultSubobject<UBoxComponent>(TEXT("CollisionComp"));
	CollisionComp->AttachTo(RootComponent);
	RootComponent = WeaponMesh;
	WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh"));
	WeaponMesh->MeshComponentUpdateFlag = EMeshComponentUpdateFlag::OnlyTickPoseWhenRendered;
	WeaponMesh->bChartDistanceFactor = true;
	WeaponMesh->bReceivesDecals = true;
	WeaponMesh->CastShadow = true;
	WeaponMesh->SetCollisionObjectType(ECC_WorldDynamic);
	WeaponMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
	WeaponMesh->SetCollisionResponseToAllChannels(ECR_Ignore);
	WeaponMesh->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);
	
	CanPickUp = true;

	// 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;
	UE_LOG(LogTemp, Warning, TEXT("I have Created a weapon"));
	CollisionComp->SetSimulatePhysics(true);
	
	//CollisionComp->SetCollisionObjectType(ECC_WorldDynamic);
	CollisionComp->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
	//CollisionComp->SetCollisionResponseToAllChannels(ECR_Block);
	//CollisionComp->SetCollisionResponseToChannel(ECC_Visibility, ECR_Overlap);
	//CollisionComp->SetCollisionResponseToChannel(ECC_Camera, ECR_Overlap);
	CollisionComp->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block);
	CollisionComp->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Block);
	//CollisionComp->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
	//CollisionComp->SetCollisionResponseToChannel(ECC_PhysicsBody, ECR_Block);
	//CollisionComp->SetCollisionResponseToChannel(ECC_Vehicle, ECR_Block);
	//CollisionComp->SetCollisionResponseToChannel(ECC_Destructible, ECR_Block);
	

	
}



I think you may need to change the order:



	WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh"));
	RootComponent = WeaponMesh;

	CollisionComp = CreateDefaultSubobject<UBoxComponent>(TEXT("CollisionComp"));
	CollisionComp->AttachTo(RootComponent);

// ther rest of WeaponMesh initialization code