Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Actor on server are invisible on clients

I am trying to spawn weapons on server and attaching it to the clients but I am not able to do so.

The weapons don't appear visible to the clients.

Here is my code.

     void APSETPCCharacter::BeginPlay()
         if (Role == ROLE_Authority)
     void APSETPCCharacter::SpawnDefaultWeapon()
         if (Role < ROLE_Authority)
         if (DefaultWeapon)
             UWorld* World = GetWorld();
             if (World)
                 ABaseWeapon* TempWeapon = GetWorld()->SpawnActor<ABaseWeapon>(DefaultWeapon);
                 CurrentWeapon = TempWeapon;

And the weapon attachment is called from OnEquip() function like this.

     void ABaseWeapon::OnEquip()
         /** Do weapon equip things bla */
     void ABaseWeapon::OnWeaponSpawn()
         GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "QWeqwe");
         ItemMesh->AttachTo(OwningPawn->GetMesh(), FName(TEXT("WeaponSocket_Rifle")));

Some addition constructor changes I made to the weapon are

     ItemMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("Weapon"));
     RootComponent = ItemMesh;
     PrimaryActorTick.bCanEverTick = true;
     bReplicates = true;
     bNetUseOwnerRelevancy = true;

Product Version: Not Selected
more ▼

asked Dec 16 '14 at 01:19 AM in C++ Programming

avatar image

423 77 117 148

avatar image envenger Dec 16 '14 at 02:46 AM

alt text

The weapons appears to have been by a ghost on the client side. The weapon moves even if the client doesn't move.

capture.jpg (96.7 kB)
avatar image envenger Dec 16 '14 at 10:21 AM

link text

Shows more exactly what is happening.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

We had this exact same problem in The Dead Linger, and in TheVOID.

What happens is that on the server the weapon is created, then the equip event is called to equip it, which also gets sent to the client. Then the client gets the equip event, then the client gets the weapon create. (Notice the client weapon create is AFTER the equip event so it never gets equipped. It ends up sitting at 0,0,0 in the world usually.)

What you have to do is have a variable on the weapon like OwnerPlayer (and maybe also an EquipSocket variable) and make them replicated and make OwnerPlayer be Rep_Notify. Then right after the spawn on the server, set the OwnerPlayer (and EquipSocket if you have that too). In the Rep_Notify do the socket attachment.

Now just after the weapon gets created the rep notify gets called and it equips.

In The Dead Linger we set both an owning player and the equip socket. In TheVOID there is only one possible socket so we don't have that variable.

more ▼

answered Nov 02 '15 at 05:08 PM

avatar image

SND R Keene
968 31 120 113

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question