Improbable Icon

UE4 Authority change


#1

So we had some hard time understanding the documentation about:

But we managed to find a way to change the authority, so if this helps anyone, here’s what we did:

First, when we spawn the entity, we had to add this inside the entityTemplate “.SetEntityAclComponentWriteAccess(ownClientRequirementSet)”

Then the object needed to have “class UEntityAclComponent* EntityAclComponent;” in header and “EntityAclComponent = CreateDefaultSubobject(TEXT(“EntityAclComponent”));” in its constructor.

And finally the code that did the actual authority change:

WorkerAttributeSet unrealWorkerAttributeSet{ { worker::List<std::string>{"UnrealWorker"} } };
	WorkerRequirementSet unrealWorkerWritePermission{ { unrealWorkerAttributeSet } };
	UWorkerRequirementSet *workerReqSet = NewObject<UWorkerRequirementSet>()->Init(unrealWorkerWritePermission);
	UEntityAclComponentUpdate *aclUpdate = NewObject<UEntityAclComponentUpdate>();
	UStdUint32TToImprobableWorkerRequirementSetMap *reqMap = createdTower->EntityAclComponent->GetComponentWriteAcl();

	worker::Map<uint32_t, WorkerRequirementSet> map;
	map.emplace(static_cast<std::uint32_t>(createdTower->EntityAclComponent->GetComponentId().ToSpatialComponentId()), unrealWorkerWritePermission);
	map.emplace(static_cast<std::uint32_t>(createdTower->TowerComponent->GetComponentId().ToSpatialComponentId()), unrealWorkerWritePermission);
	map.emplace(static_cast<std::uint32_t>(createdTower->UnitComponent->GetComponentId().ToSpatialComponentId()), unrealWorkerWritePermission);
	map.emplace(static_cast<std::uint32_t>(createdTower->UnitMovementComponent->GetComponentId().ToSpatialComponentId()), unrealWorkerWritePermission);
	map.emplace(static_cast<std::uint32_t>(createdTower->PositionComponent->GetComponentId().ToSpatialComponentId()), unrealWorkerWritePermission);
	reqMap->Init(map);
	
	aclUpdate->SetComponentWriteAcl(reqMap);

	createdTower->EntityAclComponent->SendComponentUpdate(aclUpdate);
	createdTower->EntityAclComponent->TriggerManualComponentUpdate();

Not sure if this could be done any easier/other way, but the documentation didn’t really help.