Skip to main content

1.2.0

A lot of API changes for Hypernex.Unity to work correctly. It is important that developers and creators read this (and the 2024.03.1b update) to understand what needs to be updated.

Changes

  • Removed Player Object and Weight caching
    • This was a huge waste of memory, without this, servers will be much more optimized
  • Added PlayerDataUpdate
    • Meant to update Tags and Extraneous data from the client
  • PlayerObjectUpdate is now only available as an array of objects
    • This is to reduce bandwidth with compression
  • Added MathF
  • Added ScriptEvent.OnPlayerUpdate
  • Added ScriptEvent.OnWeight
  • Added ScriptEvent.OnPlayerTags
  • Added ScriptEvent.OnPlayerExtraneousObject
  • Added VRIK properties to PlayerUpdate
    • IsFBT (bool)
      • Whether the player is playing VR with Full-Body Tracking
    • VRIKJson (string)
      • The VRIK CalibrationData serialized as a JSON string
  • Renamed NetPlayers to Instance
  • Removed NetPlayer
  • Fixed issue where Hypernex.Networking.Server would not exit when given the exit command
  • Bumped Nexport to 1.5.0

API Changes

Removal of NetPlayer

The NetPlayer class has been removed; however, it was replaced with events. This allows developers to still get data as they need, but instead, they cache what they need. The following script demonstrates how to cache the last user position.

/*
* An example player object would look like
* {
* "userId": "user_0000...",
* "NetworkedObject": null
* }
*/
let playerData = []

function getPlayerPosition(userId){
for(let i = 0; i < playerData.length; i++){
let p = playerData[i]
if(p.userId === userId){
return p.NetworkedObject.Position
}
}
return undefined
}

Events.Subscribe(ScriptEvent.OnNetworkedObject, (userId, coreBone, networkedObject) => {
// For our example, we only want the root
if(coreBone != CoreBone.Root) return;
let found = false;
for(let i = 0; i < playerData.length; i++){
let p = playerData[i]
if(p.userId === userId){
// If the object already exists, overwrite the current data
p.NetworkedObject = networkedObject
found = true
break
}
}
if(!found){
// The object did not exist, create a new one
let newP = {
"userId": userId,
"NetworkedObject": networkedObject
}
// Add the object to our cache
playerData.push(newP)
}
})

// Remove our Player cache after they leave to not waste memory
Events.Subscribe(ScriptEvent.OnUserLeave, userId => {
let newPlayers = []
for(let i = 0; i < playerData.length; i++){
let p = playerData[i]
if(p.userId === userId) continue
newPlayers.push(p)
}
playerData = newPlayers
})

Renaming of NetPlayers to Instance

Currently, this API only gets user-specific data; however, will be expanded for more information.

Here's what a script could look like

local host = Players.HostId
if host == nil or host == "" then return end
print("The host is "..host)

And the new version

local host = Instance.HostId
if host == nil or host == "" then return end
print("The host is "..host)