#need some help trying to transfer from a mainmenu scene to a freeroam scene and spawning my characte

1 messages · Page 1 of 1 (latest)

topaz thunder
#

I have a bike game at the moment and i have two scenes - mainmenu and freeroam. if i load the freeroam scene straight away then everything works fine and the bike prefab spawns in fine and works. however when i go play mainmenu and then click the freeroam mode which then transfers me to the freeroam scene it spawns the bike but i cant move it in anyway. trying to use ai to help but no luck

rugged nebula
#

the host should be changing scenes after calling StartHost()
I would also look into using sessions to cut down on code

gloomy lantern
# topaz thunder I have a bike game at the moment and i have two scenes - mainmenu and freeroam. ...

Hey, I was looking at you're issue you are having, I believe that the network objects and behaviors detected in the seen, needs fixing.

  1. You would need to verify the object ownership is correctly assigned to each of the players on scene load

2: For the input system. The player inputs components were detected right, but that needs fixing to so just confirm the input that its only processed by the owning player which is the authority check right.

The other stuff I believe that is good you have that doesn't need fixing is the physics system, rendering and light, and your build configuration.

So basically you know when the player moves between scenes the game looses track of which player controls which object. So I fixed that issue which re-assigns the control correctly on every time the scene loads

So I just replaced your SceneLobbyHost.cs With BikeNetworkManager.cs
I added the BikeController.cs to your bike prefab
Made sure that your bike prefab has NetworkObject Component
Tehn I assign the bikePrefab in the BikeNetworkManager Inspector right

So go head and test it out do the mainmeny click freeroam and your bike shouldspawn and be controllable

Also just for more understanding the SpawnwithOwnership() makes sure the clients owns the bike.

The BikeController only proccess the input when IsOwner = true
and yeah also it handles the scens transitons without breaking the netowkring connections

gloomy lantern
#

@topaz thunder Also you can refer to the documenation here https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.4/manual/basics/networkbehaviour.html

This handles the lifecycle network behavior
So the methods On-Networkspawn-GainedOwnerShip-LostOwnerShip

Networkspawn Calls after the network object is spawn
GainedOwnership Is called when ownership is assigned to the client

LostOwnership Is called when ownership is removed

This is the Spawnwithownership https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@1.7/api/Unity.Netcode.NetworkObject.SpawnWithOwnership.html

Object ownership is main issue here

https://docs-multiplayer.unity3d.com/netcode/current/basics/networkobject/

This helps alot to NGO netcode stuff

https://learn.unity.com/tutorial/get-started-with-netcode-for-gameobjects

Networkobjects ownership and authority is here to

https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.5/manual/basics/ownership.html

That talks about server ownership, client ownership assigned, Distrubted authory pattern, Ownerclientid propety, and the IsOwner checks

Then this https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.0/api/Unity.Netcode.NetworkObject.html

is like spawnwithownshiper ownerclientid propert Isownedbyserever props ownership changing

Yeah sorry this is alot haha feel like im at work (writting all this part) I am used to zoom calls and share screens when doing code review and stuff. LOL but i love helping its my passion but last is the

https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@2.5/manual/tutorials/get-started-with-ngo.html

how ownership works and player objects spawn pattern and client server authority etc examples

Unity Learn

By the end of this tutorial, users will have acquired a fundamental understanding of Netcode for GameObjects and know how to employ it when creating a casual co-op multiplayer game. This includes the effective use of the NetworkManager component and the methods used to spawn objects at the Host/Client/Server side. The tutorial provides practical...