Merge pull request #4261 from aws-lumberyard-dev/MPSpawnableHolderUpdate

Updated NetworkSpawnableHolderComponent to use TransformBus instead o…
monroegm-disable-blank-issue-2
SergeyAMZN 4 years ago committed by GitHub
commit 66a875bf79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -207,12 +207,6 @@ namespace AZ
ActivateComponent(**it);
}
// Cache the transform interface to the transform interface
// Generally this pattern is not recommended unless for component event buses
// As we have a guarantee (by design) that components can't change during active state)
// Even though technically they can connect disconnect from the bus.
m_transform = TransformBus::FindFirstHandler(m_id);
SetState(State::Active);
EBUS_EVENT_ID(m_id, EntityBus, OnEntityActivated, m_id);
@ -1320,6 +1314,19 @@ namespace AZ
return *processSignature;
}
AZ::TransformInterface* Entity::GetTransform() const
{
// Lazy evaluation of the cached entity transform.
if(!m_transform)
{
// Generally this pattern is not recommended unless for component event buses
// As we have a guarantee (by design) that components can't change during active state)
// Even though technically they can connect disconnect from the bus.
m_transform = TransformBus::FindFirstHandler(m_id);
}
return m_transform;
}
//=========================================================================
// MakeId
// Ids must be unique across a project at authoring time. Runtime doesn't matter

@ -354,10 +354,9 @@ namespace AZ
//! @return The Process Signature of the local machine.
static AZ::u32 GetProcessSignature();
/// @cond EXCLUDE_DOCS
//! @deprecated Use the TransformBus to communicate with the TransformInterface.
inline TransformInterface* GetTransform() const { return m_transform; }
/// @endcond
//! Gets the TransformInterface for the entity.
//! @return The TransformInterface for the entity.
TransformInterface* GetTransform() const;
//! Sorts an entity's components based on the dependencies between components.
//! If all dependencies are met, the required services can be activated
@ -406,7 +405,7 @@ namespace AZ
//! A cached pointer to the transform interface.
//! We recommend using AZ::TransformBus and caching locally instead of accessing
//! the transform interface directly through this pointer.
TransformInterface* m_transform;
mutable TransformInterface* m_transform;
//! A user-friendly name for the entity. This makes error messages easier to read.
AZStd::string m_name;

@ -24,6 +24,13 @@ namespace Multiplayer
}
}
void NetworkSpawnableHolderComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
{
// TransformService isn't strictly required in this component (Identity transform will be used by default)
// However we need to make sure if there's a component providing TransformService it is activated first.
dependent.push_back(AZ_CRC_CE("TransformService"));
}
NetworkSpawnableHolderComponent::NetworkSpawnableHolderComponent()
{
}
@ -38,11 +45,9 @@ namespace Multiplayer
{
AZ::Transform rootEntityTransform = AZ::Transform::CreateIdentity();
AzFramework::TransformComponent* rootEntityTransformComponent =
GetEntity()->FindComponent<AzFramework::TransformComponent>();
if (rootEntityTransformComponent)
if(auto* transformInterface = GetEntity()->GetTransform())
{
rootEntityTransform = rootEntityTransformComponent->GetWorldTM();
rootEntityTransform = transformInterface->GetWorldTM();
}
INetworkEntityManager* networkEntityManager = GetNetworkEntityManager();

@ -22,11 +22,12 @@ namespace Multiplayer
public:
AZ_COMPONENT(NetworkSpawnableHolderComponent, "{B0E3ADEE-FCB4-4A32-8D4F-6920F1CB08E4}");
static void Reflect(AZ::ReflectContext* context);
NetworkSpawnableHolderComponent();;
~NetworkSpawnableHolderComponent() override = default;
static void Reflect(AZ::ReflectContext* context);
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
//! AZ::Component overrides.
//! @{
void Activate() override;

Loading…
Cancel
Save