MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / SetObjectOwnership

Method SetObjectOwnership

Source/Engine/Networking/NetworkReplicator.cpp:1690–1793  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1688}
1689
1690void NetworkReplicator::SetObjectOwnership(ScriptingObject* obj, uint32 ownerClientId, NetworkObjectRole localRole, bool hierarchical)
1691{
1692 if (!obj || NetworkManager::IsOffline())
1693 return;
1694 const Guid objectId = obj->GetID();
1695 ScopeLock lock(ObjectsLock);
1696 const auto it = Objects.Find(objectId);
1697 if (it == Objects.End())
1698 {
1699 // Special case if we're just spawning this object
1700 for (int32 i = 0; i < SpawnQueue.Count(); i++)
1701 {
1702 auto& item = SpawnQueue[i];
1703 if (item.Object == obj)
1704 {
1705#if !BUILD_RELEASE
1706 if (ownerClientId == NetworkManager::LocalClientId)
1707 {
1708 // Ensure local client owns that object actually
1709 if (localRole != NetworkObjectRole::OwnedAuthoritative)
1710 {
1711 LOG(Error, "Cannot change ownership of object (Id={}) to the local client (Id={}) if the local role is not set to OwnedAuthoritative.", obj->GetID(), ownerClientId);
1712 return;
1713 }
1714 }
1715 else
1716 {
1717 // Ensure local client doesn't own that object since it's owned by other client
1718 if (localRole == NetworkObjectRole::OwnedAuthoritative)
1719 {
1720 LOG(Error, "Cannot change ownership of object (Id={}) to the remote client (Id={}) if the local role is set to OwnedAuthoritative.", obj->GetID(), ownerClientId);
1721 return;
1722 }
1723 }
1724#endif
1725 item.HasOwnership = true;
1726 item.HierarchicalOwnership = hierarchical;
1727 item.OwnerClientId = ownerClientId;
1728 item.Role = localRole;
1729 break;
1730 }
1731 }
1732 }
1733 else
1734 {
1735 auto& item = it->Item;
1736 if (item.Object != obj)
1737 return;
1738
1739 // Check if this client is object owner
1740 if (item.OwnerClientId == NetworkManager::LocalClientId)
1741 {
1742 // Check if object owner will change
1743 if (item.OwnerClientId != ownerClientId)
1744 {
1745 // Change role locally
1746#if !BUILD_RELEASE
1747 if (localRole == NetworkObjectRole::OwnedAuthoritative)

Callers

nothing calls this directly

Calls 10

IsOfflineFunction · 0.85
SendObjectRoleMessageFunction · 0.85
IsParentOfFunction · 0.85
GetIDMethod · 0.80
FindMethod · 0.45
EndMethod · 0.45
CountMethod · 0.45
RemoveObjectMethod · 0.45
ClearMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected