Hello Guest

Author Topic: Mesh collider's mesh disappearing on play  (Read 4363 times)

dpk

  • Newbie
  • *
  • Posts: 13
    • View Profile
Mesh collider's mesh disappearing on play
« on: June 08, 2013, 02:55:19 am »
I have a sprite batch containing a set of walls and stuff that I want to use as obstacles (ultimately using the A* Pathfinding Project: http://arongranberg.com/astar/docs/getstarted.php). In order to get the pathfinding system to recognize the walls as obstacles, I have to attach a mesh collider. When I attach a mesh collider and re-scan the scene everything seems to work right -- the obstacles are recognized as impassable -- but when I click play the mesh collider's mesh disappears. If I reset the mesh collider the mesh reappears but only until the next time I click play.

I tried this with a sprite batch and with a regular ol' sprite, same result. This doesn't seem to happen with other objects outside of the 2D Toolkit. Any idea what I might be doing wrong? I'm hoping this rings a bell for someone.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mesh collider's mesh disappearing on play
« Reply #1 on: June 08, 2013, 11:16:57 am »
If you attach a mesh to the actual static sprite batcher object, it will likely get wiped out as the static sprite batcher will try to create one for its own use - in this case, if you didn't have anything it'll delete it as it thinks its surplus from the previous state.

A good way to work around this is to make an empty game object parent of the static sprite batcher, and attach the mesh collider to that instead.

dpk

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Mesh collider's mesh disappearing on play
« Reply #2 on: June 08, 2013, 04:52:39 pm »
OK, I'll give that a shot. Do you have tips on how to get the mesh collider to use the child object's mesh?

dpk

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Mesh collider's mesh disappearing on play
« Reply #3 on: June 08, 2013, 06:05:06 pm »
I found a way. Sorta. I added a new menu option to Assets that allows me to save a mesh to a file. So, the workflow is:

* Create the sprite batcher
* Add sprites to it, position 'em
* Click commit in the sprite batcher
* Add a mesh collider to the sprite batcher
* Save the mesh (Select the sprite batcher, then go to Assets -> Save -> Mesh)
* Delete the mesh collider from the sprite batcher
* Add a new empty game object, make it the parent of the sprite batcher. Fix the positions.
* Add a mesh collider to the new parent. Drag the saved mesh to the mesh collider's "mesh" selector.

You'll need to repeat the last few steps every time you change the sprite batcher contents.

I've attached the script I made. It's my first editor script, it may not be right, but it's a start.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mesh collider's mesh disappearing on play
« Reply #4 on: June 08, 2013, 10:15:58 pm »
That will work, more or less. Its one of those really annoying things you've gotta deal with when working with dynamic meshes :(
Edit: Well - trying to process dynamic meshes statically...