Unity editor Bake functions differently to scripted break.
See original GitHub issueI’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:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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’
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 callingBuildNavMesh()
.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!