buildTo(Locatable a).step() will throw an NPE sometimes

Discussion in 'Developer Support' started by Dibes, Jun 24, 2015.

  1. Dibes

    Joined:
    Nov 18, 2013
    Messages:
    117
    Likes Received:
    8
    When I run this code it sometimes throws an NPE and I can't figure out why

    Code (Text):
    1.  GameObject obelisk = GameObjects.newQuery().names("Small obelisk").results().first();
    2.         if (obelisk != null && !obelisk.isVisible()) {
    3.             Traversal.getDefaultWeb().getPathBuilder().buildTo(obelisk.getPosition()).step();
    4.             Camera.passivelyTurnTo(obelisk);
    5.         }
     
  2. Cloud

    Cloud Just another one...

    Joined:
    Jul 28, 2013
    Messages:
    2,470
    Likes Received:
    835
    You're not null checking your path. If a path can't be generated it'll return null.
     
  3. Dibes

    Joined:
    Nov 18, 2013
    Messages:
    117
    Likes Received:
    8
    Ah thanks! I didn't know that :)
     

Share This Page

Loading...