Hello, how can I use HasAuthority() inside an ActorComponent()?
void UInventoryComponent::AddInventoryItem(FItemData ItemData)
{
if (HasAuthority())
{
InventoryItems.Add(ItemData);
if (IsLocallyControlled())
{
OnRep_InventoryItems();
}
}
}
Hello, how can I use HasAuthority() inside an ActorComponent()?
void UInventoryComponent::AddInventoryItem(FItemData ItemData)
{
if (HasAuthority())
{
InventoryItems.Add(ItemData);
if (IsLocallyControlled())
{
OnRep_InventoryItems();
}
}
}
AActor* Owner = GetOwner();
if (Owner && Owner->HasAuthority())
{
// ...
}
Also there is an easier solution.
if(GetOwnerRole() == ROLE_Authority)