Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question is LoadObjectAsync reference counted?

Discussion in 'Entity Component System' started by Mohamed-Anis, Oct 1, 2023.

  1. Mohamed-Anis

    Mohamed-Anis

    Joined:
    Jun 14, 2013
    Posts:
    94
    Hi!

    Looking at Class RuntimeContentManager | Entities | 1.0.16 (unity3d.com), I can't tell if LoadObjectAsync/ReleaseObjectAsync is reference counted or not. E.g. what happens if there's a request to LoadObjectAsync that happens in one thread while ReleaseObjectAsync (for the same Mesh or Material) happens in another thread (i.e. releasing a previous request for the resource)? Will the new LoadObjectAsync fail if it happens to execute just before the ReleaseObjectAsync?

    Thank you!
     
  2. PeppeJ10C

    PeppeJ10C

    Joined:
    Jun 9, 2022
    Posts:
    6
    Yes they are, directly from 1.0.16 source:

    Unity.Entities.Content.WeakObjectReference<TObject>.LoadAsync
    Code (CSharp):
    1. /// <summary>
    2. /// Directs the object to begin loading.  This will increase the reference count for each call to the same id.  Release must be called for each Load call to properly release resources.
    3. /// </summary>
    4. public void LoadAsync()
    5. {
    6.     RuntimeContentManager.LoadObjectAsync(Id);
    7. }