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

Method OnDeleteObject

Source/Engine/Content/Asset.cpp:273–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271}
272
273void Asset::OnDeleteObject()
274{
275 ASSERT(IsInMainThread());
276
277 // Send event to the gameplay so it can release handle to this asset
278 // This may happen when asset gets removed but sth is still referencing it (eg. in managed code)
279 if (!IsInternalType())
280 Content::AssetDisposing(this);
281
282 const bool wasMarkedToDelete = _deleteFileOnUnload != 0;
283#if USE_EDITOR
284 const String path = wasMarkedToDelete ? String(GetPath()) : String::Empty;
285#endif
286 const Guid id = GetID();
287
288 // Fire unload event (every object referencing this asset or it's data should release reference so later actions are safe)
289 onUnload_MainThread();
290
291 // Remove from pool
292 Content::onAssetUnload(this);
293
294 // Unload asset data (in a safe way to protect asset data)
295 Locker.Lock();
296 if (IsLoaded())
297 {
298 unload(false);
299 Platform::AtomicStore(&_loadState, (int64)LoadState::Unloaded);
300 }
301 Locker.Unlock();
302
303#if BUILD_DEBUG
304 // Ensure no object is referencing it (except managed instance if exists)
305 //ASSERT(_refCount == (HasManagedInstance() ? 1 : 0));
306#endif
307
308 // Base (after it `this` is invalid)
309 ManagedScriptingObject::OnDeleteObject();
310
311#if USE_EDITOR
312 if (wasMarkedToDelete)
313 {
314 LOG(Info, "Deleting asset '{0}':{1}.", path, id.ToString());
315
316 // Remove from registry
317 Content::GetRegistry()->DeleteAsset(id, nullptr);
318
319 // Delete file
320 if (!IsVirtual())
321 Content::deleteFileSafety(path, &id);
322 }
323#endif
324}
325
326bool Asset::CreateManaged()
327{

Callers 2

FlushMethod · 0.45
DisposeMethod · 0.45

Calls 12

IsInMainThreadFunction · 0.85
GetPathFunction · 0.85
GetIDFunction · 0.85
OnDeleteObjectFunction · 0.85
IsVirtualFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
IsLoadedFunction · 0.70
StringClass · 0.50
AtomicStoreFunction · 0.50
ToStringMethod · 0.45
DeleteAssetMethod · 0.45

Tested by

no test coverage detected