diff --git a/Assets/Editor/Translation/scriptcanvas_en_us.ts b/Assets/Editor/Translation/scriptcanvas_en_us.ts index a7d29e2dbc..5cafabaf60 100644 --- a/Assets/Editor/Translation/scriptcanvas_en_us.ts +++ b/Assets/Editor/Translation/scriptcanvas_en_us.ts @@ -14679,6 +14679,25 @@ An Entity can be selected by using the pick button, or by dragging an Entity fro + + Method: NetBindComponent + + NETBINDCOMPONENT_ISNETENTITYROLEAUTHORITY_TOOLTIP + Returns true if this network entity is an authoritative proxy on a server (full authority); otherwise false. + + + NETBINDCOMPONENT_ISNETENTITYROLEAUTONOMOUS_TOOLTIP + Returns true if this network entity is an autonomous proxy on a client (can execute local prediction) or if this network entity is an authoritative proxy on a server but has autonomous privileges (ie: a host who is also a player); otherwise false. + + + NETBINDCOMPONENT_ISNETENTITYROLECLIENT_TOOLTIP + Returns true if this network entity is a simulated proxy on a client; otherwise false. + + + NETBINDCOMPONENT_ISNETENTITYROLESERVER_TOOLTIP + Returns true if this network entity is a simulated proxy on a server (ie: a different server may own this entity, but the entity has been replicated to this server; otherwise false. + + Method: Math diff --git a/Gems/Multiplayer/Code/Include/Multiplayer/Components/MultiplayerComponent.h b/Gems/Multiplayer/Code/Include/Multiplayer/Components/MultiplayerComponent.h index 19689171c5..9f2f9f4804 100644 --- a/Gems/Multiplayer/Code/Include/Multiplayer/Components/MultiplayerComponent.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/Components/MultiplayerComponent.h @@ -63,10 +63,10 @@ namespace Multiplayer //! @} NetEntityId GetNetEntityId() const; - bool IsAuthority() const; - bool IsAutonomous() const; - bool IsServer() const; - bool IsClient() const; + bool IsNetEntityRoleAuthority() const; + bool IsNetEntityRoleAutonomous() const; + bool IsNetEntityRoleServer() const; + bool IsNetEntityRoleClient() const; ConstNetworkEntityHandle GetEntityHandle() const; NetworkEntityHandle GetEntityHandle(); void MarkDirty(); diff --git a/Gems/Multiplayer/Code/Include/Multiplayer/Components/NetBindComponent.h b/Gems/Multiplayer/Code/Include/Multiplayer/Components/NetBindComponent.h index 7d9b7d4086..dd4b9588e4 100644 --- a/Gems/Multiplayer/Code/Include/Multiplayer/Components/NetBindComponent.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/Components/NetBindComponent.h @@ -64,10 +64,23 @@ namespace Multiplayer //! @} NetEntityRole GetNetEntityRole() const; - bool IsAuthority() const; - bool IsAutonomous() const; - bool IsServer() const; - bool IsClient() const; + + //! IsNetEntityRoleAuthority + //! @return true if this network entity is an authoritative proxy on a server (full authority); otherwise false. + bool IsNetEntityRoleAuthority() const; + + //! IsNetEntityRoleAutonomous + //! @return true if this network entity is an autonomous proxy on a client (can execute local prediction) or if this network entity is an authoritative proxy on a server but has autonomous privileges (ie: a host who is also a player); otherwise false. + bool IsNetEntityRoleAutonomous() const; + + //! IsNetEntityRoleServer + //! @return true if this network entity is a simulated proxy on a server (ie: a different server may have authority for this entity, but the entity has been replicated on this server; otherwise false. + bool IsNetEntityRoleServer() const; + + //! IsNetEntityRoleClient + //! @return true if this network entity is a simulated proxy on a client; otherwise false. + bool IsNetEntityRoleClient() const; + bool HasController() const; NetEntityId GetNetEntityId() const; const PrefabEntityId& GetPrefabEntityId() const; diff --git a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.cpp b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.cpp index 8542288b23..2ad883c7e7 100644 --- a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.cpp +++ b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.cpp @@ -46,24 +46,24 @@ namespace Multiplayer return m_netBindComponent ? m_netBindComponent->GetNetEntityId() : InvalidNetEntityId; } - bool MultiplayerComponent::IsAuthority() const + bool MultiplayerComponent::IsNetEntityRoleAuthority() const { - return m_netBindComponent ? m_netBindComponent->IsAuthority() : false; + return m_netBindComponent ? m_netBindComponent->IsNetEntityRoleAuthority() : false; } - bool MultiplayerComponent::IsAutonomous() const + bool MultiplayerComponent::IsNetEntityRoleAutonomous() const { - return m_netBindComponent ? m_netBindComponent->IsAutonomous() : false; + return m_netBindComponent ? m_netBindComponent->IsNetEntityRoleAutonomous() : false; } - bool MultiplayerComponent::IsServer() const + bool MultiplayerComponent::IsNetEntityRoleServer() const { - return m_netBindComponent ? m_netBindComponent->IsServer() : false; + return m_netBindComponent ? m_netBindComponent->IsNetEntityRoleServer() : false; } - bool MultiplayerComponent::IsClient() const + bool MultiplayerComponent::IsNetEntityRoleClient() const { - return m_netBindComponent ? m_netBindComponent->IsClient() : false; + return m_netBindComponent ? m_netBindComponent->IsNetEntityRoleClient() : false; } ConstNetworkEntityHandle MultiplayerComponent::GetEntityHandle() const diff --git a/Gems/Multiplayer/Code/Source/Components/MultiplayerController.cpp b/Gems/Multiplayer/Code/Source/Components/MultiplayerController.cpp index b0bafccf79..071dfd4ee2 100644 --- a/Gems/Multiplayer/Code/Source/Components/MultiplayerController.cpp +++ b/Gems/Multiplayer/Code/Source/Components/MultiplayerController.cpp @@ -29,12 +29,12 @@ namespace Multiplayer bool MultiplayerController::IsAuthority() const { - return GetNetBindComponent() ? GetNetBindComponent()->IsAuthority() : false; + return GetNetBindComponent() ? GetNetBindComponent()->IsNetEntityRoleAuthority() : false; } bool MultiplayerController::IsAutonomous() const { - return GetNetBindComponent() ? GetNetBindComponent()->IsAutonomous() : false; + return GetNetBindComponent() ? GetNetBindComponent()->IsNetEntityRoleAutonomous() : false; } AZ::Entity* MultiplayerController::GetEntity() const diff --git a/Gems/Multiplayer/Code/Source/Components/NetBindComponent.cpp b/Gems/Multiplayer/Code/Source/Components/NetBindComponent.cpp index 0847d42dd6..d5e83e5751 100644 --- a/Gems/Multiplayer/Code/Source/Components/NetBindComponent.cpp +++ b/Gems/Multiplayer/Code/Source/Components/NetBindComponent.cpp @@ -54,69 +54,72 @@ namespace Multiplayer ->Attribute(AZ::Script::Attributes::Module, "multiplayer") ->Attribute(AZ::Script::Attributes::Category, "Multiplayer") - ->Method("IsAuthority", [](AZ::EntityId id) -> bool { + ->Method("IsNetEntityRoleAuthority", [](AZ::EntityId id) -> bool { AZ::Entity* entity = AZ::Interface::Get()->FindEntity(id); if (!entity) { - AZ_Warning( "NetBindComponent", false, "NetBindComponent IsAuthority failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str()) + AZ_Warning( "NetBindComponent", false, "NetBindComponent IsNetEntityRoleAuthority failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str()) return false; } NetBindComponent* netBindComponent = entity-> FindComponent(); if (!netBindComponent) { - AZ_Warning( "NetBindComponent", false, "NetBindComponent IsAuthority failed. Entity '%s' (id: %s) is missing a NetBindComponent, make sure this entity contains a component which derives from NetBindComponent.", entity->GetName().c_str(), id.ToString().c_str()) + AZ_Warning( "NetBindComponent", false, "NetBindComponent IsNetEntityRoleAuthority failed. Entity '%s' (id: %s) is missing a NetBindComponent, make sure this entity contains a component which derives from NetBindComponent.", entity->GetName().c_str(), id.ToString().c_str()) return false; } - return netBindComponent->IsAuthority(); + return netBindComponent->IsNetEntityRoleAuthority(); }) - ->Method("IsAutonomous", [](AZ::EntityId id) -> bool { + + ->Method("IsNetEntityRoleAutonomous", [](AZ::EntityId id) -> bool { AZ::Entity* entity = AZ::Interface::Get()->FindEntity(id); if (!entity) { - AZ_Warning( "NetBindComponent", false, "NetBindComponent IsAutonomous failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str()) + AZ_Warning( "NetBindComponent", false, "NetBindComponent IsNetEntityRoleAutonomous failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str()) return false; } NetBindComponent* netBindComponent = entity->FindComponent(); if (!netBindComponent) { - AZ_Warning("NetBindComponent", false, "NetBindComponent IsAutonomous failed. Entity '%s' (id: %s) is missing a NetBindComponent, make sure this entity contains a component which derives from NetBindComponent.", entity->GetName().c_str(), id.ToString().c_str()) + AZ_Warning("NetBindComponent", false, "NetBindComponent IsNetEntityRoleAutonomous failed. Entity '%s' (id: %s) is missing a NetBindComponent, make sure this entity contains a component which derives from NetBindComponent.", entity->GetName().c_str(), id.ToString().c_str()) return false; } - return netBindComponent->IsAutonomous(); + return netBindComponent->IsNetEntityRoleAutonomous(); }) - ->Method("IsClient", [](AZ::EntityId id) -> bool { + + ->Method("IsNetEntityRoleClient", [](AZ::EntityId id) -> bool { AZ::Entity* entity = AZ::Interface::Get()->FindEntity(id); if (!entity) { - AZ_Warning( "NetBindComponent", false, "NetBindComponent IsClient failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str()) + AZ_Warning( "NetBindComponent", false, "NetBindComponent IsNetEntityRoleClient failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str()) return false; } NetBindComponent* netBindComponent = entity->FindComponent(); if (!netBindComponent) { - AZ_Warning("NetBindComponent", false, "NetBindComponent IsClient failed. Entity '%s' (id: %s) is missing a NetBindComponent, make sure this entity contains a component which derives from NetBindComponent.", entity->GetName().c_str(), id.ToString().c_str()) + AZ_Warning("NetBindComponent", false, "NetBindComponent IsNetEntityRoleClient failed. Entity '%s' (id: %s) is missing a NetBindComponent, make sure this entity contains a component which derives from NetBindComponent.", entity->GetName().c_str(), id.ToString().c_str()) return false; } - return netBindComponent->IsClient(); + return netBindComponent->IsNetEntityRoleClient(); }) - ->Method("IsServer", [](AZ::EntityId id) -> bool { + + ->Method("IsNetEntityRoleServer", [](AZ::EntityId id) -> bool { AZ::Entity* entity = AZ::Interface::Get()->FindEntity(id); if (!entity) { - AZ_Warning( "NetBindComponent", false, "NetBindComponent IsServer failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str()) + AZ_Warning( "NetBindComponent", false, "NetBindComponent IsNetEntityRoleServer failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str()) return false; } NetBindComponent* netBindComponent = entity->FindComponent(); if (!netBindComponent) { - AZ_Warning("NetBindComponent", false, "NetBindComponent IsServer failed. Entity '%s' (id: %s) is missing a NetBindComponent, make sure this entity contains a component which derives from NetBindComponent.", entity->GetName().c_str(), id.ToString().c_str()) + AZ_Warning("NetBindComponent", false, "NetBindComponent IsNetEntityRoleServer failed. Entity '%s' (id: %s) is missing a NetBindComponent, make sure this entity contains a component which derives from NetBindComponent.", entity->GetName().c_str(), id.ToString().c_str()) return false; } - return netBindComponent->IsServer(); + return netBindComponent->IsNetEntityRoleServer(); }) ; } @@ -179,23 +182,23 @@ namespace Multiplayer return m_netEntityRole; } - bool NetBindComponent::IsAuthority() const + bool NetBindComponent::IsNetEntityRoleAuthority() const { return (m_netEntityRole == NetEntityRole::Authority); } - bool NetBindComponent::IsAutonomous() const + bool NetBindComponent::IsNetEntityRoleAutonomous() const { return (m_netEntityRole == NetEntityRole::Autonomous) || (m_netEntityRole == NetEntityRole::Authority) && m_allowAutonomy; } - bool NetBindComponent::IsServer() const + bool NetBindComponent::IsNetEntityRoleServer() const { return (m_netEntityRole == NetEntityRole::Server); } - bool NetBindComponent::IsClient() const + bool NetBindComponent::IsNetEntityRoleClient() const { return (m_netEntityRole == NetEntityRole::Client); } diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp index b0f1b221e8..3405abdc57 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp @@ -96,7 +96,7 @@ namespace Multiplayer { AZ_Assert(entityHandle.GetNetBindComponent(), "No NetBindComponent found on networked entity"); [[maybe_unused]] const bool isClientOnlyEntity = false;// (ServerIdFromEntityId(it->first) == InvalidHostId); - AZ_Assert(entityHandle.GetNetBindComponent()->IsAuthority() || isClientOnlyEntity, "Trying to delete a proxy entity, this will lead to issues deserializing entity updates"); + AZ_Assert(entityHandle.GetNetBindComponent()->IsNetEntityRoleAuthority() || isClientOnlyEntity, "Trying to delete a proxy entity, this will lead to issues deserializing entity updates"); } m_removeList.push_back(entityHandle.GetNetEntityId()); m_removeEntitiesEvent.Enqueue(AZ::TimeMs{ 0 });