You should check that the WorldObject is actually an Unit before using ToUnit()