Skip to main content
flarb
Up and Coming
May 5, 2025
Question

GetUserPerisistentVarWithNullFallback argument at position 0 was the server player

I'm trying to set a player variable, and I get this error:

 

Error Handling Event:
Error: Exception encountered running bridge method 'GetUserPersistentVarWithNullFallback': GetUserPersistentVarWithNullFallback argument at position 0 was the server player, which is not supported in this method
    at Object.invoke (horizon-global.js:156:23)
    at Object.getPlayerVariable (file://horizon/horizon/core/HorizonCore.js:6490:36)
    at NPCMonster.onProjectileHitMe (NPCMonster.ts:90:56)
    at NPCMonster.ts:72:11
    at file://horizon/horizon/core/HorizonCore.js:7604:24
    at Function.TracingIntegration.trace [as trace] (file://horizon/horizon/core/HorizonCore.js:7833:9)
    at file://horizon/horizon/core/HorizonCore.js:7599:32

The code  in question is a broadcast event I emit from my projectile script for the projectile shooter gizmo. When it hits an entity I send the event like this:

  private onProjectileHitEntity(entity: Entity, position: Vec3, normal: Vec3) {

    this.sendNetworkBroadcastEvent(ProjectileHitMe, { player: this.props.projectileLauncher!.owner.get(), entity: entity });
    this.onHitGeneric(position, normal);
  }

And in the broadcastevent handler for my monster I try and set a player var using that owner player parameter:

  private onProjectileHitMe(player : hz.Player, entity : hz.Entity) {

    console.log("projectile hit entity");

    if (entity == this.entity) {
      this.hit();

      let blastedZombies = this.world.persistentStorage.getPlayerVariable(player, "ChickenPlayers:BlastedZombies");
      this.world.persistentStorage.setPlayerVariable(player, "ChickenPlayers:BlastedPlayers", blastedZombies + 1);
    }
  }

This script is using default execution. So I'm not sure why it doesn't like the player I'm passing in--is the owner player on the projectile shooter gizmo not the right player object to use?

3 replies

ExoGuid
Honored Contributor
May 5, 2025

Still learning, but will hazard a guess. Does sending player and receiving hz.Player matter?

I'd try connecting the local event and making sure your payload is formatted correctly

const hitplayerEvent = new LocalEvent<{ player: Player }>('hitplayer');
this.connectLocalEvent(this.entity, hitplayerEvent, this.onPlayerHit.bind(this));

 

Beyond that, maybe add a:

private player!: Player;

and when you receive your event:  

this.player = player

and get/set your playervariables with this.player

 

flarb
flarbAuthor
Up and Coming
May 5, 2025

So you can make these both local and broadcast events? This event system is kind of confusing. 

Also, I'm not quite sure what you mean about adding a private player member. On which object?

I'm guessing Player and hz.Player are the same..it's just that the script that uses Player explicitly imports it from horizon/core.

@flarb
SeeingBlue
Honored Contributor
May 5, 2025

The error suggest your player wasn't set properly in the variable you used. It came back as serverPlayer, which is a null player basically. We can continue this one in the discord if you want.

Upcoming Events : Performance Pro - UI Unleashed - Building Responsive & Performant Interfaces Thursday June 19th 5:00 PM PT - Register June Programming Calendar