Forum Discussion

Mike_BigBrother's avatar
1 month ago
Solved

Typescript, transfer ownership not working.

Hello smart people, the Desktop editor's AI tool, GPT and i have spent 5 days on this and we can't seem to get this working. Long story short, i have a 'local' weapon script that works flawlessly with vfx, sfx, projectile gizmo, events to Hud etc when used by player 1. However, the moment player 2, they cannot fire the weapon.

I've added tons of debugging logs and the concensus is proper ownership transfer. However, the weapon entity, the individual connected entities etc are all in the transfer ownership section of the script.

Desktop editor's AI, GPT and i are stumped.

I know you're probably going to want to see an example script and try to make suggestions but to be honest, ive tried so many iterations, even copying 'Chop 'n' Pop' version, watching limited tutorials on this subject , etc and still not working for player 2.

Id be happy to clone the world and have someone connect to it and try, see whats going on. Might be the best way to figure it out.

id be happy to post results here afterwards. 

Like i said, AI in desktop editor hadn't been able to figure it out. It had me going in circles on day 3. :) 

You can reply here or ping me in Worlds for a deeper discussion.

i appreciate ya

BB

  • As a summary to the overall issue i had, yes GauRoth came and updated a few things that appear to have worked in our testing but it wasn't so much of an ownership issue than it was a lack of ammo for the player during our testing.

    However, the issue i had experienced continued when testing between myself (Creator of the world) and a World tester. The tester still was not able to fire. I had continued down the path of ownership based on the console logs but remembered GauRoth saying that the ownership was fine (sharing the weapon between he and I worked - 2 world creators).
    Then it hit me... a few months ago, there was an update that did not allow testerd to fire their weapon in Test environments (Sandboxes). So i went ahead and privetly published the world and sure enough, ithe weapon fired for the Tester and other guests that i invited. So GausRoth was right when he said, it wasnt an ownership issue. 

7 Replies

  • Without looking at the world or script, I can't be sure but if you only have one object with the local script attached only one player can be the owner. If you have more than one object you need to ensure you're not transferring ownership to the same one.

    For example: you will need a hud for each player. On the hud script have a props definition for playerIndex of type number. In the huds properties panel set them to a different number ranging from 0-max player length - 1 (if your max player count is 5 then have 5 HUD with a player index of 0-4)

    In the on player enter world event check the players index and if it matches the playerIndex value assign ownership and connect to your events using the player as the target. This way you can just send the event to the player and the correct hud will receive it.

    • Mike_BigBrother's avatar
      Mike_BigBrother
      Member

      Hi Gausroth. I follow your videos and they helped me a lot. Thank you for that.

      Here is the situation.
      I have one weapon object. It has three scripts tied together.

      • MemWeapon2 handles grab events, cooldowns, ammo requests, and ownership transfer.
      • MemoryProjectile handles projectile hits.
      • MemoryRaycastScope runs local and positions the reticle based on hand data.

      The HUD is server driven. It reads game state from MemoryGameController.
      The weapon sends fire requests to the controller.
      The controller sends results back and the weapon spawns the projectile.

      Everything works for player one.
      Player two grabs the weapon and the reticle follows their hand.
      The grab event fires.
      Ownership moves to that player.
      The HUD updates.
      But the trigger pull does nothing.

      This is the ownership section inside the weapon script.
      This is the short version.

      private transferOwnershipTo(p: hz.Player) {
        const ents = [
          this.entity,
          this.props.projectileLauncher,
          this.props.raycastIndicatorObject,
          this.props.grabSfx,
          this.props.fireSfx,
          this.props.dryFireSfx,
          this.props.muzzleVfx
        ];
      
        for (const e of ents) {
          if (e) e.owner.set(p);
        }
      }

      I checked the patterns from ownerDataTransferExample.
      I also verified that only one local script exists.
      MemoryRaycastScope runs local and only moves visuals.

      If needed, I can clone the world and let you inspect it live.
      If you prefer, I can share a trimmed down version of the script here.
      I'm available all day today to try and figure this out. Yes, its day 7 today! lol

      BB

  • I transfer ownerships all the time. And tbh the AI is quite dumb so i never use it, it often give flawed suggestions and mess up my stuff. But without ur code theres no way to know where u messed up

    • Madios,

      Thanks for the reply.
      I agree with your point about the AI.
      It gives ideas, but I trust live testing more.

      Here is the setup.
      One weapon object with these scripts:

      • MemWeapon2 controls grab, trigger pulls, fire requests, and ownership transfer.
      • MemoryProjectile handles hit events and sends them to the tile.
      • MemoryRaycastScope runs local and positions a reticle based on hand direction.
      • MemoryGameController receives fire events and controls ammo and matches.
      • MemoryGameHud shows ammo, moves, matches, and messages.

      Player one works every time.
      Player two can grab the weapon.
      Ownership transfers.
      HUD events run.
      Raycast visuals follow their hand.
      Trigger pull never fires.

      Here is the short form of the ownership transfer section.

      private transferOwnershipTo(p: hz.Player) {
        const ents = [
          this.entity,
          this.props.projectileLauncher,
          this.props.raycastIndicatorObject,
          this.props.grabSfx,
          this.props.fireSfx,
          this.props.dryFireSfx,
          this.props.muzzleVfx
        ];
      
        for (const e of ents) {
          if (e) e.owner.set(p);
        }
      }

      If you want, I can post the full weapon script. (but i think there may be more going one than just the 1 script. , but what do i know? lol, its only been 6 days on this!)


      BB

      • Madlios's avatar
        Madlios
        Member

        The transferring seems right but because once u transfer all scripts will reset so that's where it might break, gonna need to see the other related scripts too. Have u tried printing to console to see where things are actually triggered?

  • As a summary to the overall issue i had, yes GauRoth came and updated a few things that appear to have worked in our testing but it wasn't so much of an ownership issue than it was a lack of ammo for the player during our testing.

    However, the issue i had experienced continued when testing between myself (Creator of the world) and a World tester. The tester still was not able to fire. I had continued down the path of ownership based on the console logs but remembered GauRoth saying that the ownership was fine (sharing the weapon between he and I worked - 2 world creators).
    Then it hit me... a few months ago, there was an update that did not allow testerd to fire their weapon in Test environments (Sandboxes). So i went ahead and privetly published the world and sure enough, ithe weapon fired for the Tester and other guests that i invited. So GausRoth was right when he said, it wasnt an ownership issue.