To ensure a few things, Yes I have a socket named Weapon_Socket on my character skeletal mesh, I ensured the Collision checks are working… Spawning the mesh is fine, but when I try to Attach the mesh to the socket on the Character, It crashes the Editor.
I have tried a more simplified situation. I ensured that the CCD is off on all of the components. both the character and the object that is being touched as well… It’s still crashing the engine . here’s the basic code for the situation.
weapon.h
// Fill out your copyright notice in the Description page of Project Settings.
void ATesterCharacter::OnCollision(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
{
AWeapon* Weapon = Cast<AWeapon>(OtherActor);
if (Weapon)
{
GEngine->AddOnScreenDebugMessage(-1, 4.f, FColor::Green, "HELLO IM A WEAPON!!");
SpawnWeapon(Weapon->GetClass());
Weapon->Destroy();
}
}
void ATesterCharacter::SpawnWeapon(TSubclassOf<class AWeapon> Weapon)
{
AWeapon* Spawner = GetWorld()->SpawnActor<AWeapon>(Weapon);
if (Spawner)
{
GEngine->AddOnScreenDebugMessage(-1, 4.f, FColor::Green, "I SPAWNED");
Spawner->AttachRootComponentTo(Mesh, "Weapon_Socket", EAttachLocation::SnapToTarget);
}
}
most of the comments can only fit soo much… but relatively, It’s slimmer, but the same situation… The object spawns just fine, just wont attach to socket even the SetLocation wont work… and i turned off the CCD by unchecking the Use CCD checkmark in the collisions Here
Still at a standstill figuring out why it’s not working
Update - I tried putting the socket farther away from the mesh, and it works just fine… but I want the mesh to be attached closer because it needs to be attached to the hand Dx. even with the CCD off, it still crashes
Any new news about this bug? because my only temporary solution I have for now is doing this to the mesh before attaching it… I had to delete the UBoxComponent in general right when it spawned
void AWeaponEssentialsCharacter::SpawnWeapon(TSubclassOf<AWeapon> Weapon)
{
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = Instigator;
AWeapon *Spawner = GetWorld()->SpawnActor<AWeapon>(Weapon);
if (Spawner)
{
Spawner->CollisionComp->DestroyComponent();//WITHOUT THIS, THE EDITOR WILL CRASH!!!!!
Spawner->AttachRootComponentTo(Mesh, FName(TEXT("Weapon_Socket")), EAttachLocation::SnapToTarget);
}
}
KEEP IN MIND! I switched my mesh to a skeletal mesh… static mesh still has this issue!!!
UPDATE:
if you set the collision to NoCollision when you spawn the Static mesh, It will work too… It’s the temporary fix for now I believe