Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed (Author was flagged for spam)

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

0
gun not attaching to character in multiplayer mode
Post Body

whats happening: https://imgur.com/a/yayn7jT

header declaration:

    UFUNCTION(BlueprintCallable,Server,reliable)
        void EquipGun(TSubclassOf<class AGun> Gun);

code:

EquipGun:

void APlayerCharacter::EquipGun_Implementation(TSubclassOf<class AGun> Gun)
{
    if (IsValid(EquipedGun))
    {
        GetWorld()->DestroyActor(EquipedGun);
    }

    EquipedGun = Cast<AGun>(GetWorld()->SpawnActor(Gun));
    EquipedGun->AttachToComponent(GetMesh(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, EAttachmentRule::KeepWorld, false), TEXT("hand_l"));

    EquipedGun->SetActorRelativeLocation(EquipedGun->LocationOffset);
    EquipedGun->SetActorRelativeScale3D(EquipedGun->SizeOffset);
    EquipedGun->SetActorRelativeRotation(EquipedGun->RotationOffset);
}

replication stuff:

void APlayerCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty >& OutLifetimeProps) const
{
    Super::GetLifetimeReplicatedProps(OutLifetimeProps);


    DOREPLIFETIME(APlayerCharacter, Health);
    DOREPLIFETIME(APlayerCharacter, EquipedGun);
    DOREPLIFETIME(APlayerCharacter, Crouching);
    DOREPLIFETIME(APlayerCharacter, GetControlRotation());

}

Gun.cpp

AGun::AGun()
{
    // 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;
    CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
    CameraComp->SetupAttachment(GetRootComponent());
    Mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Mesh"));

    bReplicates = true;

}

// Called when the game starts or when spawned
void AGun::BeginPlay()
{
    Super::BeginPlay();
    CurrentAmmo = MaxAmmo;

}

// Called every frame
void AGun::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

}

Author
Account Strength
0%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
34,548
Link Karma
9,973
Comment Karma
23,263
Profile updated: 7 months ago
Posts updated: 8 months ago
Young Dev(17)

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago