I created a UActorComponent * InventoryComponent in my APlayerState, which has a weapon array. When I enter the Dedicated server, the array always contains null elements when Replicated to the client, but the size of the array is correct.
When the delegate of PlayerState, OnPawnSet, was called on Dedicated, I created weapon Actors and added them to the WeaponAry.
Here is createWeapon code:
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
SpawnInfo.Owner = GetOwner();
TempWeapon = SpawnWeaponWorld->SpawnActor<AWeaponBase>(i,SpawnInfo);
if(IsValid(TempWeapon))
{
//初始化武器数据
TempWeapon->InitWeapon(Character);
//TempWeapon->SetOwner(GetOwner());
//绑定装备回调
TempWeapon->OnEquipComplete.BindUObject(this,&UWFInventoryComponent::OnWeaponEquipComplete);
//绑定卸载回调
TempWeapon->OnDetachComplete.BindUObject(this,&UWFInventoryComponent::OnWeaponDetachComplete);
TempWeapon->OnEquipStart.BindUObject(this,&UWFInventoryComponent::OnWeaponEquipStart);
//将武器添加至武器数组
WeaponAry.AddUnique(TempWeapon);
APlayerState.h:
APlayerState.cpp:
UWFInventoryComponent.h:
UWFInventoryComponent.cpp: