[BUG] Gizmos do not render when A* component is loaded additively with scene

  • A* version: 5.4.5
  • Unity version: 6000.0.58f2

Hi there.

Reproduction steps:

  1. Set up a fresh project (URP in my case), import A* and its samples and Burst and Entities etc.
  2. Add the A* sample scene “Recast3D” to the Build scene list.
  3. Set up a scene so it only contains a gameobject with this script component:
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LoadRecastScene : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(LoadCo());
    }
    
    private IEnumerator LoadCo()
    {
        yield return new WaitForSeconds(2.0f);
        SceneManager.LoadScene("Recast3D", LoadSceneMode.Additive);
    }
}

The Gizmos of the AStarPath component will never render, this is because of the line here:

if (!script.gameObject.scene.IsValid()) {
    // The object is likely part of a persistent prefab asset. We will never have to draw any gizmos for it, because it will never become enabled, and it will never show up in the scene view.
    continue;
}

in DrawingManager.cs:615

This will cause it to never be queued into the custom Gizmo rendering system.

Best regards

Alex Nogueira

1 Like

Thanks for posting! I did some looking around and what I’m understanding is that IsValid() is just, on top of being underdocumented, is just sorta… weirdly mistmatch with what the user expects it to spit out vs what is reality. I’ll tag Aron on this to take a look though. Thanks again!

1 Like

Thanks for your response, yeah IsValid() is not documented very well :s

After a quick check I think the underlying issue is that the registration is called within the constructor, which is not really something that Unity particularily likes or even supports. The Engine much prefers the provided Awake/Start/OnEnable methods, which would assure Scene validity.

1 Like

Great find!

I have switched to PrefabUtility.IsPartOfPrefabAsset(script) now, which seems to work better (and is also faster, surprisingly enough). I’ll include the fix in the next update.

1 Like