fix: Prevent m_AssetId set to empty string (#2766)

* fix: Prevent m_AssetId set to empty string
Fixes: #2765

Checks path for empty string before assigning to `m_AssetId`.

I left commented debug logs in place from testing, which was setting `NetworkIdentity.ServerOnly` on and off both in normal edit mode and prefab edit mode. In either mode, OnValdidate fires 4 times, and two of those try to set an empty string to `m_AssetId`.

* Changes as requested

* Update Assets/Mirror/Runtime/NetworkIdentity.cs

* Update NetworkIdentity.cs

Co-authored-by: vis2k <info@noobtuts.com>
This commit is contained in:
MrGadget 2021-06-15 04:10:42 -04:00 committed by GitHub
parent b08cc62fd4
commit 8218979e32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -328,7 +328,13 @@ void OnValidate()
}
#if UNITY_EDITOR
void AssignAssetID(string path) => m_AssetId = AssetDatabase.AssetPathToGUID(path);
void AssignAssetID(string path)
{
// only set if not empty. fixes https://github.com/vis2k/Mirror/issues/2765
if (!string.IsNullOrEmpty(path))
m_AssetId = AssetDatabase.AssetPathToGUID(path);
}
void AssignAssetID(GameObject prefab) => AssignAssetID(AssetDatabase.GetAssetPath(prefab));
// persistent sceneId assignment