Add NetworkReplicator.AddObjectIdMapping for global/custom network objects sync

#3042
This commit is contained in:
Wojtek Figat
2024-11-05 16:37:23 +01:00
parent 6f694daf92
commit 853e7cb6f7
2 changed files with 15 additions and 0 deletions

View File

@@ -1311,6 +1311,14 @@ void NetworkReplicator::MapObjectId(Guid& objectId)
}
}
void NetworkReplicator::AddObjectIdMapping(const ScriptingObject* obj, const Guid& objectId)
{
CHECK(obj);
const Guid id = obj->GetID();
NETWORK_REPLICATOR_LOG(Info, "[NetworkReplicator] Remap object ID={} into object {}:{}", objectId, id.ToString(), obj->GetType().ToString());
IdsRemappingTable[objectId] = id;
}
ScriptingObject* NetworkReplicator::ResolveForeignObject(Guid objectId)
{
if (const auto& object = ResolveObject(objectId))

View File

@@ -122,6 +122,13 @@ public:
/// </summary>
/// <param name="objectId">The network object identifier to map. Contains result ID once the method completes.</param>
API_FUNCTION() static void MapObjectId(API_PARAM(Ref) Guid& objectId);
/// <summary>
/// Adds a new mapping for object identifier. Can be used to link locally-spawned object with across different clients.
/// </summary>
/// <param name="obj">The network object.</param>
/// <param name="objectId">The network object identifier to use (eg. defined by server or global/static).</param>
API_FUNCTION() static void AddObjectIdMapping(const ScriptingObject* obj, API_PARAM(Ref) const Guid& objectId);
/// <summary>
/// Resolves foreign Guid into a local ScriptingObject