I though if I used the deferred method to spawn and actor, the actor in question would be created (and replicated) with the changes made to it.
However I'm having trouble with it.
On server side everything works as planned, the weapons are created with owner associated with them. However on the client, the weapons are created without owner, which is only replicated after its creation. Is my assumption wrong about the replication of actors creating using the deferred method?
However I'm having trouble with it.
Code:
void UWeaponSystemComponent::SpawnDefaultInventory(){ if (GetOwnerRole() == ROLE_Authority){ for (auto WeaponClass : DefaultInventoryClasses){ AWeapon* NewWeapon = GetWorld()->SpawnActorDeferred<AWeapon>(WeaponClass, FVector(), FRotator(), GetOwner(), GetOwner()->Instigator); AddWeapon(NewWeapon); UGameplayStatics::FinishSpawningActor(NewWeapon, NewWeapon->GetTransform()); } } } void UWeaponSystemComponent::AddWeapon(AWeapon* Weapon){ if (Weapon && GetOwnerRole() == ROLE_Authority ){ // set the owner of the inventory/weapon Weapon->OnEnterInventory(Cast<ASoldier>(GetOwner())); Inventory.AddUnique(Weapon); // if no weapon is currently is equipped, equip this one if (CurrentWeapon == NULL){ EquipWeapon(Weapon); } } }
Comment