All TArray elements replicated to the client are null

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:

TArray elements replicated to the client are null

Likely means that array was replicated properly, but there were no corresponding actors for those pointers(netids) found on the client.

As a possible reason, the AWeaponBase actors can be not set to be replicatable at all. If that’s the case, just check the proper checkbox. There are some other possible reasons, but lets start from simple things first.

I found the Key. Calling SetNetAddressable() in AWeapon will cause this Actor to fail to Replicated

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.