diff --git a/Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntity/INetworkEntityManager.h b/Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntity/INetworkEntityManager.h index 991aef4d38..8a5fec869c 100644 --- a/Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntity/INetworkEntityManager.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntity/INetworkEntityManager.h @@ -59,7 +59,8 @@ namespace Multiplayer ( const PrefabEntityId& prefabEntryId, NetEntityRole netEntityRole, - const AZ::Transform& transform + const AZ::Transform& transform, + AutoActivate autoActivate = AutoActivate::Activate ) = 0; //! Creates new entities of the given archetype diff --git a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp index 497d35db7e..b0a8350982 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp +++ b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp @@ -643,6 +643,7 @@ namespace Multiplayer { controlledEntity.GetNetBindComponent()->SetOwningConnectionId(connection->GetConnectionId()); } + controlledEntity.Activate(); if (connection->GetUserData() == nullptr) // Only add user data if the connect event handler has not already done so { @@ -763,6 +764,7 @@ namespace Multiplayer { controlledEntityNetBindComponent->SetAllowAutonomy(true); } + controlledEntity.Activate(); } AZLOG_INFO("Multiplayer operating in %s mode", GetEnumString(m_agentType)); @@ -969,7 +971,7 @@ namespace Multiplayer NetworkEntityHandle MultiplayerSystemComponent::SpawnDefaultPlayerPrefab() { PrefabEntityId playerPrefabEntityId(AZ::Name(static_cast(sv_defaultPlayerSpawnAsset).c_str())); - INetworkEntityManager::EntityList entityList = m_networkEntityManager.CreateEntitiesImmediate(playerPrefabEntityId, NetEntityRole::Authority, AZ::Transform::CreateIdentity()); + INetworkEntityManager::EntityList entityList = m_networkEntityManager.CreateEntitiesImmediate(playerPrefabEntityId, NetEntityRole::Authority, AZ::Transform::CreateIdentity(), Multiplayer::AutoActivate::DoNotActivate); NetworkEntityHandle controlledEntity; if (entityList.size() > 0) diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp index 05373bbeee..69d2726c65 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp @@ -309,7 +309,7 @@ namespace Multiplayer } INetworkEntityManager::EntityList NetworkEntityManager::CreateEntitiesImmediate( - const AzFramework::Spawnable& spawnable, NetEntityRole netEntityRole) + const AzFramework::Spawnable& spawnable, NetEntityRole netEntityRole, AutoActivate autoActivate) { INetworkEntityManager::EntityList returnList; @@ -359,6 +359,11 @@ namespace Multiplayer const NetEntityId netEntityId = NextId(); netBindComponent->PreInit(clone, prefabEntityId, netEntityId, netEntityRole); + if (autoActivate == AutoActivate::DoNotActivate) + { + clone->SetRuntimeActiveByDefault(false); + } + AzFramework::GameEntityContextRequestBus::Broadcast( &AzFramework::GameEntityContextRequestBus::Events::AddGameEntity, clone); @@ -378,10 +383,11 @@ namespace Multiplayer ( const PrefabEntityId& prefabEntryId, NetEntityRole netEntityRole, - const AZ::Transform& transform + const AZ::Transform& transform, + AutoActivate autoActivate ) { - return CreateEntitiesImmediate(prefabEntryId, NextId(), netEntityRole, AutoActivate::Activate, transform); + return CreateEntitiesImmediate(prefabEntryId, NextId(), netEntityRole, autoActivate, transform); } INetworkEntityManager::EntityList NetworkEntityManager::CreateEntitiesImmediate @@ -414,7 +420,7 @@ namespace Multiplayer if (entityIndex == PrefabEntityId::AllIndices) { - return CreateEntitiesImmediate(*netSpawnable, netEntityRole); + return CreateEntitiesImmediate(*netSpawnable, netEntityRole, autoActivate); } const AzFramework::Spawnable::EntityList& entities = netSpawnable->GetEntities(); diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h index 97db532916..9ccc576447 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h @@ -43,12 +43,13 @@ namespace Multiplayer ConstNetworkEntityHandle GetEntity(NetEntityId netEntityId) const override; NetEntityId GetNetEntityIdById(const AZ::EntityId& entityId) const override; - EntityList CreateEntitiesImmediate(const AzFramework::Spawnable& spawnable, NetEntityRole netEntityRole); + EntityList CreateEntitiesImmediate(const AzFramework::Spawnable& spawnable, NetEntityRole netEntityRole, AutoActivate autoActivate); EntityList CreateEntitiesImmediate ( const PrefabEntityId& prefabEntryId, NetEntityRole netEntityRole, - const AZ::Transform& transform + const AZ::Transform& transform, + AutoActivate autoActivate = AutoActivate::Activate ) override; EntityList CreateEntitiesImmediate (