question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unity editor Bake functions differently to scripted break.

See original GitHub issue

I’m developing some 2D isometric world generation logic using NavMeshSurface2d and NavMeshModifer scripts. So far, all the tile colliders have worked ok when baked with the script (calling NavMeshSurface2d.BuildNavMesh).

However, when adding a GameObject to the mix which has it’s own polygon collider, the script call to bake the mesh does not include the gameobjects’ colliders. When I generate the world, then press bake from the UI the colliders are baked fine.

Is there a reason it would work from the GUI but not scripted? Could it be a timing issue? Do I need to ‘construct’ the colliders somehow?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
h8mancommented, Feb 17, 2021

@GitFlip ,

You certainly right. I getting more and more question about baking at runtime, so many other users may encounter this. I will add this info to wiki

Wiki updated

Issue ‘resolved’

0reactions
GitFlipcommented, Feb 17, 2021

Thanks for the suggestions @h8man.

I decided to take the approach of understanding why the collider is getting updated correctly at a later point and time, and ran into some good documentation about the collider’s bounds not getting updated to match the transform until LateUpdate() is called.

How we were generating things was instantiating the prefab, setting the transform of this new game object, and eventually programmatically baking. This all happened then before LateUpdate() was called and so the collider’s bounds were never updated even though the transform of the game object was.

To remedy this I simply forced the update by calling Physics2D.SyncTransforms() before calling BuildNavMesh().

FYI: https://docs.unity3d.com/ScriptReference/Physics2D.SyncTransforms.html

So I think that this issue can be closed, but maybe this info is worth mentioning somewhere? Not sure if you really need to though as it’s a fundamental part of Unity Physics not NavMeshPlus.

Thanks again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Workaround] Changing Unity Editor "Baked Agent Size" ...
Is there a way how I can either change the default navmesh agent size in the editor navigation window from a script, or...
Read more >
Scripting API: Lightmapping.BakeMultipleScenes
Manual · Scripting API ... The function automatically splits baked data by Scene. ... At build time this data will also be automatically...
Read more >
Event Functions
Event Functions. A script in Unity is not like the traditional idea of a program where the code runs continuously in a loop...
Read more >
Objects in Scene dark after calling LoadScene/LoadLevel
It sometimes looks like this for a few seconds after opening unity when the editor is loading. Here is the script:
Read more >
Baking Shaders into Textures
First we let the script inherit from the EditorWindow class, ... using UnityEditor; public class BakeTextureWindow : EditorWindow ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found