Search Unity

Object reference not set to an instance of the Object

Discussion in 'Scripting' started by PrieDayThor, Jun 18, 2015.

  1. PrieDayThor

    PrieDayThor

    Joined:
    Jun 18, 2015
    Posts:
    16
    Hey guys,

    so I'm trying to build a Tower which spawns 3 "bears" and calls the function MoveToLocation in the BearScript.
    The BearScript is attached to the bear prefab but if I start the "game" I get the error: Object reference not set to an instance of the Object.
    I already looked it up in the internet and did everything which was described there but still it doesnt work.
    Pls help me :)

    BearScript: http://pastebin.com/2CCdDqqf
    BearSpawnScript: http://pastebin.com/7BmnhJ9U

    Regarts
    Prie
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    and that error tells you which script and which line number... which are?

    did you set any waypoints in the inspector?
     
  3. PrieDayThor

    PrieDayThor

    Joined:
    Jun 18, 2015
    Posts:
    16
  4. GargerathSunman

    GargerathSunman

    Joined:
    May 1, 2008
    Posts:
    1,571
    Do you have the variable "myWayPoint" initialized by anything? The error seems to be that "myWayPoint" is null when the script is run, at least for one frame.
     
  5. PrieDayThor

    PrieDayThor

    Joined:
    Jun 18, 2015
    Posts:
    16
    Well I changed my script but still it's not working...
    I really don't get it.
    Does somebody have an idea for a workaround?

    Script attachted to an empty GameObject: http://pastebin.com/E7zGvCXG
    Script attachted to the bearObject: http://pastebin.com/qT9ajGGC

    As you can see the waypoints are in a list in the spawnerscript.. and I guess they are inizialized when the script runs..
     
  6. PrieDayThor

    PrieDayThor

    Joined:
    Jun 18, 2015
    Posts:
    16
    So I tested a bit and found out that that the error occurs through the waypoints.