Author Topic: Migrating from UNet to TNet: What's involved?  (Read 2658 times)

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Migrating from UNet to TNet: What's involved?
« on: November 12, 2016, 04:14:01 AM »
Greetings,

I'm using a third party asset from Opsive called the Third Person Controller and it has networking functionality such as an authoritative server that utilizes the default UNet stack. However, the problem is that UNet has a bug in it's Network Animator that stops characters from working correctly if I start a Network Server in LAN/Dedicated Mode as I want to be able to have a server running and not have to have a "player object" taking up room on the server slots. After research and hair pulling, I put the cards on the table and remembered I had a license of TNet I could use.

From what I see in the Third Person Controller's networking side of things, it uses a fair amount of UNet RPCs such as [Command] and [ClientRpc]. Most objects that need to be sent over the network have NetworkIdentities and NetworkTransform scripts attached to them, etc.

I know I'm possibly looking at a lot of code refactoring, but if UNet is going to give me pain I'd rather have TNet handling the network side of my game. Perhaps has someone already written a wrapper for this kit? Is it worth pursuing or should I just keep using UNet since the third party asset already has it working out of the box?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Migrating from UNet to TNet: What's involved?
« Reply #1 on: November 13, 2016, 05:45:18 PM »
I'd be the wrong person to ask as I rarely use 3rd party assets -- and when I do I somehow end up partly rewriting them. I think the least asset I've touched that I've used was the Time of Day, only having changed about 10% of it.

I'm using TNet 3 here for my current still-unnamed W2 project, so I'm still adding to it / expanding it a fair bit. If you do undertake the task of switching, I can answer questions related to how to do X or Y. I doubt I'll be of much help with anything related to UNet though.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Migrating from UNet to TNet: What's involved?
« Reply #2 on: November 14, 2016, 08:06:20 PM »
Migrating from UNet to TNet wasn't too difficult if I recall correctly. However, I wasn't using 3rd party assets, so I was very familiar with all the code.
[RFC] replaces [ClientRpc] and [Command]. To make it execute on the host (like the Command attribute) you simply check TNManager.isHosting.
[SyncVar] doesn't exist, but you can use tno.Send with the Target.AllSaved to achieve the same functionality. Except you have more control now because you control how often it's synced.
I'm sure there's more that I'm forgetting, but in the end I think you'll find TNet comes with much less hair pulling than UNet. If you do decide to make the switch, be sure to check out the tutorials to familiarize yourself.

Oh, one important thing: TNet isn't server-authoritative. The host has authority. You could probably fake server authority by making the host a dummy, headless client, but I felt it's important to mention that. I don't think you'll find a network solution that's actually server-authoritative. It's (probably?) impossible to make a one-size-fits-all server-authoritative solution, as it's very game-dependent. Regardless, though, you can absolutely rewrite TNet to be server-authoritative - Aren has the most wonderful coding style I've ever seen - as everything is very extensible and simple to customize, but it is a big undertaking nonetheless.

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: Migrating from UNet to TNet: What's involved?
« Reply #3 on: November 15, 2016, 02:33:06 AM »
You could scratch the Network Animator and write your own animation functionality.  Use [Command] to activate your animations separately when the animation parameters changes. Kinda like how you would do it on TNet.