So I have a factory for creating objects based on RakNet's NetworkIDObjects. If it's the authority then it will just create a new object, otherwise it will create the object then set the Net ID:
std::shared_ptr<CNetObject> CNetObjectFactory::Create(int netObjectType, bool IsAuthority, RakNet::NetworkID networkID) const
{
auto entry = m_RegisteredObjects.find(netObjectType);
auto clone = std::shared_ptr<CNetObject>(entry->second->Clone());
clone->SetNetworkIDManager(m_NetworkIDManager.get());
if (IsAuthority)
{
clone->SetAuthority();
}
else if (networkID != 0)
{
clone->SetNetworkID(networkID);
}
return clone;
}
This works fine for the first couple of NetObjects spawned on the client, but the third one always crashes inside SetNetworkID:
Assertion Failed! nio->GetNetworkID()!=rawId
With the following callstack:
MyApp.exe!RakNet::NetworkIDManager::TrackNetworkIDObject(class RakNet::NetworkIDObject *) Unknown
MyApp.exe!RakNet::NetworkIDObject::SetNetworkID(unsigned __int64) Unknown
MyApp.exe!CNetObjectFactory::Create(int netObjectType, bool IsAuthority, unsigned __int64 networkID) Line 42 C++
I can't find any information about this error anywhere else, nor can I figure out what is different about this particular object. The NetworkIDs seem no different to the previous objects (except it's increased by one). As far as I can tell there's nothing obvious that can be causing this crash.