Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
Don't update shadow data if we created the entity locally (#687)
Browse files Browse the repository at this point in the history
* Fixed shadow data being incorrectly reinitialized

* Delete qq

* PR feedback

* Fix compilation
  • Loading branch information
Vatyx committed Feb 26, 2019
1 parent 71c56e0 commit eea26aa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ USpatialActorChannel::USpatialActorChannel(const FObjectInitializer& ObjectIniti
, NetDriver(nullptr)
, LastSpatialPosition(FVector::ZeroVector)
, bCreatingNewEntity(false)
, bCreatedEntity(false)
{
}

Expand Down Expand Up @@ -160,6 +161,15 @@ void USpatialActorChannel::UpdateShadowData()
{
check(Actor);

// If this channel was responsible for creating the channel, we do not want to initialize our shadow data
// to the latest state since there could have been state that has changed between creation of the entity
// and gaining of authority. Revisit this with UNR-1034
// TODO: UNR-1029 - log when the shadow data differs from the current state of the Actor.
if (bCreatedEntity)
{
return;
}

// Refresh shadow data when crossing over servers to prevent stale/out-of-date data.
ActorReplicator->RepLayout->InitShadowData(ActorReplicator->ChangelistMgr->GetRepChangelistState()->StaticBuffer, Actor->GetClass(), (uint8*)Actor);

Expand Down Expand Up @@ -714,6 +724,7 @@ void USpatialActorChannel::OnCreateEntityResponse(const Worker_CreateEntityRespo
return;
}

bCreatedEntity = true;
UE_LOG(LogSpatialActorChannel, Verbose, TEXT("Created entity (%lld) for: %s."), Op.entity_id, *Actor->GetName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ void USpatialReceiver::HandleActorAuthority(Worker_AuthorityChangeOp& Op)
}
else if (Op.authority == WORKER_AUTHORITY_NOT_AUTHORITATIVE)
{
if (USpatialActorChannel* ActorChannel = NetDriver->GetActorChannelByEntityId(Op.entity_id))
{
ActorChannel->bCreatedEntity = false;
}

Actor->Role = ROLE_SimulatedProxy;
Actor->RemoteRole = ROLE_Authority;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ void ComponentFactory::AddProperty(Schema_Object* Object, Schema_FieldId FieldId
FUnrealObjectRef ObjectRef = FUnrealObjectRef::NULL_OBJECT_REF;

UObject* ObjectValue = ObjectProperty->GetObjectPropertyValue(Data);

if (ObjectValue != nullptr && !ObjectValue->IsPendingKill())
{
FNetworkGUID NetGUID;
Expand All @@ -204,7 +205,8 @@ void ComponentFactory::AddProperty(Schema_Object* Object, Schema_FieldId FieldId
}
}

if (NetGUID.IsValid())
// The secondary part of the check is only necessary until we have bulk reservation of entity ids UNR-673
if (NetGUID.IsValid() || (ObjectValue->IsSupportedForNetworking() && !ObjectValue->IsFullNameStableForNetworking()))
{
ObjectRef = PackageMap->GetUnrealObjectRefFromNetGUID(NetGUID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ class SPATIALGDK_API USpatialActorChannel : public UActorChannel

void UpdateShadowData();

// If this actor channel is responsible for creating a new entity, this will be set to true once the entity is created.
bool bCreatedEntity;

protected:
// UChannel Interface
virtual bool CleanUp(const bool bForDestroy) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ class SPATIALGDK_API USpatialNetDriver : public UIpNetDriver

TMap<Worker_EntityId_Key, USpatialActorChannel*> EntityToActorChannel;

// Timer manager.
FTimerManager* TimerManager;

bool bAuthoritativeDestruction;
Expand Down

0 comments on commit eea26aa

Please sign in to comment.