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 When should Mesh.MarkDynamic be called?

Discussion in 'Scripting' started by WinterboltGames, Apr 29, 2023.

  1. WinterboltGames

    WinterboltGames

    Joined:
    Jul 27, 2016
    Posts:
    257
    I'm currently prototyping a voxel terrain system and wondered when to call Mesh.MarkDynamic?

    According to the documentation (https://docs.unity3d.com/ScriptReference/Mesh.MarkDynamic.html):
    What does it mean exactly? Should I be calling Mesh.MarkDynamic every time before I call Mesh.SetVertices? Should I call it once upon mesh creation? Or should I not bother calling it at all?
     
  2. WinterboltGames

    WinterboltGames

    Joined:
    Jul 27, 2016
    Posts:
    257
    I forgot to mention that I had searched the web for an answer and couldn't find one that cleared up the confusion.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    You don't need to call it every time. If you've already called it, it'll do nothing.

    I don't believe that flag persists if the mesh is serialized however so its initial state is not dynamic.
     
    WinterboltGames likes this.
  4. WinterboltGames

    WinterboltGames

    Joined:
    Jul 27, 2016
    Posts:
    257
    Thanks for your reply.

    So, If I understand correctly now, I should call it once upon mesh creation, right?

    Hmm, can you elaborate?
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    As it says, before you start changing it. It's a performance optimization for when you intend to continually update it. It doesn't have to be immediately after you create it.

    If you were to, say, create an asset from the mesh, it doesn't save this flag. If you're not doing that, ignore the comment.
     
    WinterboltGames likes this.