protected function getRegisteredObject(ObjectId $umi, $buildDepth, $varName) {
    if ($buildDepth == 0) {
      $buildDepth=BuildDepth::SINGLE;
    }
    $umiStr = $umi->toString();
    $objects = $this->session->get($varName);
    if (isset($objects[$umiStr]) && isset($objects[$umiStr][$buildDepth])) {
      return $objects[$umiStr][$buildDepth];
    }
    // check if an object with larger build depth was stored already
    if ($buildDepth == BuildDepth::SINGLE) {
      $existingDepths = array_keys($objects[$umiStr]);
      foreach($existingDepths as $depth) {
        if ($depth > 0 || $depth == BuildDepth::INFINITE) {
          return $objects[$umiStr][$depth];
        }
      }
    }
    return null;
  }