#Scene Manager

330 messages · Page 1 of 1 (latest)

low minnow
#

each of my player will call the LoadSceneWithLoadingScreenCoroutine method which makes them load into the specified scene, which in this instance will be the gameplay scene

#

my problem is that i tried to manually add their connection to the scene they are loading into, but im not sure if a client can do that himself

#

since fishnet apperantly also has callbacks for then a scene starts loading, the loading progress and when it finishes, i want to convert this script to use fishnet's scene management as well

#

could anyone help me do that?

#

i would still like my "Loading" scene to appear whenever the scene is loading

#

also to mention my "Bootstrap" scene is always active as the main scene, so if im loading another scene it'll have to be an additive

placid dune
# low minnow https://hastebin.com/share/dedisevoye.csharp

Hi there, I think if you have a nice setup for loading the scene already then just keep that. On the client side once the scene is loaded fully just send a broadcast to the server telling it that it's loaded and use the AddConnectionToScenes method

low minnow
#

would i need to pass in the connection as well or should this work?

placid dune
#

LocalConnection wouldn't work

#

You would either use Owner, or the connection of the caller

low minnow
#

so my scene manager is in the bootstrap which is always active, and it also has the network object

placid dune
#

I wouldn't recommend that

#

I'd recommend using a broadcast instad

#

NetworkObjects in the bootstrap scene can be messy

low minnow
#

so make it a mono behaviour?

low minnow
#

because im not sure on how to do it

low minnow
#

sorry i read through it but im still a bit confused, could you try and explain how to do it?

#

but if i do it once i'll know how to do it in the future

placid dune
#

Which part is the problem at, I can try to explain that part

#

In summary, on the server you listen for the broadcast the client will send.
InstanceFinder.ServerManager.RegisterBroadcast can be used for listening

low minnow
placid dune
#

On the client you send the broadcast with: InstanceFinder.ClientManager.Broadcast(msg);

low minnow
#

alright starting to make sense

#

didnt know this was a thing

#

thats useful as hell

placid dune
#

Yep, it can be pretty powerful

#

They can be received on multiple objects for example

low minnow
#

can i have all of this in 1 script

#

or would i have to make a seperate one for the listening

placid dune
low minnow
#

should be correct right

placid dune
#

That looks good

low minnow
#

do i not need to unregister the broadcasts?

#

like in OnDisable

placid dune
#

It's good to

low minnow
#

like you do with actions

placid dune
#

Best to do it, even though the object may be part of the bootstrap

low minnow
#

seems to work

#

thanks

#

and now i understand broadcasts as well

#

gonna make a chat system in a minute

#

one more question though

#

this is about something else

#

but i just realised its also broken

#

when spawning my player it doesnt give him the ownership of that network object

placid dune
#

It does in the Spawn call though

low minnow
#

for some reason when i spawn in as a player

#

it turns the script off for me

#

suggesting i dont have the owner

#

even though i should

placid dune
#

if you log in the first if block, does it ever print?

low minnow
#

oh wait

#

nevermind

#

it doesnt even spawn the player

#

that was just the old prefab i left in the scene

placid dune
#

ah I see

#

I guess first of all, do you have a Scene Observer Condition in your ObserverManager?

low minnow
#

i only have this

placid dune
#

Ah ok, you need to add it there

low minnow
#

what does that do

placid dune
#

it prevents the server trying to tell clients about objects they don't yet have

low minnow
#

okay i added it

#

but its still not spawning my player for some reason

#

and this is the player spawner

#

i start the connection in the lobby

#

and then the scene with the player spawner is loaded

#

OnSpawnServer isn't being called

placid dune
#

Does the Debug.Log($"[Server] Added client {conn.ClientId} to scene {msg.SceneName}"); log get printed on the server?

low minnow
#

yup

#

as in its printed in my console

placid dune
#

Is the Scene scene = UnitySceneManager.GetSceneByName(msg.SceneName); correct?

#

Can you like print the handle from that and also print the handle in the PlayerSpawner

low minnow
#

i put a debug log there

placid dune
#

right, we need to find out why, hence the scene handle checks

#

did you try printing it in Awake and the broadcast method?

placid dune
#

And on the line after you add the connection to the scene

low minnow
#

wait

#

it was because of this

#

i had both of these ticked off

placid dune
#

Oh lol

#

That would explain it

low minnow
#

do i just need the IsNetworked?

placid dune
#

I believe so

#

But it won't hurt to have both

low minnow
#

yeah now it works

#

thank you

placid dune
#

No problem, glad to hear it's working

low minnow
#

i tried destroying the player prefab from the scene

#

but its not destroying it

#

like this one

#

because i dont want to manually delete it every time

#

do i have to call despawn?

#

and in the OnSpawnServer

#

like this

placid dune
#

Why is it there?

low minnow
#

this is just when im testing

#

i wanna be able to see him in the scene

#

obviously when im going to build the game im going to delete him

#

its just to make testing easier

placid dune
#

I thought it would, I may have to look into that tomorrow

low minnow
#

but it keeps giving me this after

placid dune
low minnow
#

i think its because its already registered in fishnet as a network object in that scene

placid dune
low minnow
#

let me check when i hop on my pc

placid dune
#

So I suspect something else is referencing the script or object in some way

low minnow
# placid dune Do you have a full stack trace for that error?
MissingReferenceException: The object of type 'NetworkObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
FishNet.Object.NetworkObject.SetIsNestedThroughTraversal () (at Assets/Plugins/FishNet/Runtime/Object/NetworkObject.cs:1332)
FishNet.Managing.Server.ServerObjects.InitializeRootNetworkObjects (System.Collections.Generic.List`1[T] nobs) (at Assets/Plugins/FishNet/Runtime/Managing/Server/Object/ServerObjects.cs:382)
FishNet.Managing.Server.ServerObjects.SetupSceneObjects (System.Collections.Generic.List`1[T] sceneNobs) (at Assets/Plugins/FishNet/Runtime/Managing/Server/Object/ServerObjects.cs:443)
FishNet.Managing.Server.ServerObjects.IterateLoadedScenes (System.Boolean ignoreFrameRestriction) (at Assets/Plugins/FishNet/Runtime/Managing/Server/Object/ServerObjects.cs:343)
FishNet.Managing.Server.ServerObjects.TimeManager_OnUpdate () (at Assets/Plugins/FishNet/Runtime/Managing/Server/Object/ServerObjects.cs:110)
FishNet.Managing.Timing.TimeManager.TickUpdate () (at Assets/Plugins/FishNet/Runtime/Managing/Timing/TimeManager.cs:365)
FishNet.Transporting.NetworkReaderLoop.Update () (at Assets/Plugins/FishNet/Runtime/Transporting/NetworkReaderLoop.cs:28)
#

its coming from the network manager

placid dune
#

Ah I see, looks like nested object related

#

I'll try something related to that

low minnow
placid dune
#

Oh, thanks for the reminder, I forgot about this today 😅

low minnow
#

no problem

#

its not a big issue anyways

placid dune
#

Hmm, still no luck replicating it unfortunately. The code I have on the object is simply: Destroy(gameObject); in Awake

low minnow
#

then switching to a new scene where this player spawner is

#

and in that scene calling the Destroy in Awake?

placid dune
#

I'll try to test that when I get a chance to

low minnow
#

thanks

low minnow
#

i tried everything

#

still getting the error

#

i added a cube and slapped a network object on it

#

and tried destroying it

#

and got the error

placid dune
#

Which FishNet version is this on?

low minnow
#

that was after i stopped the game

low minnow
placid dune
low minnow
#

"version": "4.6.2",

#

pro

placid dune
#

Ok, best to try the new version then

low minnow
#

how can i update

#

without errors

low minnow
#

or do i need to remove the old one first

#

and will this break things

#

i updated it

#

still getting the error

#

now this isnt even hiding the player prefab

#

before it was hiding it

#

tf

placid dune
#

Ok, what exact steps should I follow to be able to replicate it?

low minnow
#

i'll tell you when i get home

#

sorry

placid dune
low minnow
#

and in that script trying to destroy the network object prefab of the player (the one in the scene)

#

in awake

low minnow
placid dune
low minnow
#

in Awake

#

but start the connection in a different scene

placid dune
#

Yep, I've got it happening now

#

Hopefully we can find a fix

low minnow
low minnow
low minnow
#

any luck?

placid dune
#

I'll try to do that today

low minnow
placid dune
low minnow
#

thank you so much

#

i appreciate it a lot

#

do you know in the meanwhile how i can at least hide the player prefab?

#

a work around for now

#

because when i updated the fishnet version its not even setting the object inactive

placid dune
#

Does disabling it in OnStartClient work?

placid dune
#

Destroying it from OnStartClient should actually work well

low minnow
#

let me test when u get home

low minnow
#

thank you

coral yoke
low minnow
coral yoke
#

the loby example is load buidin sceen,i want from AssetBundle

low minnow
#

im not sure

#

im not using fishnet to load the scenes

#

i made everything from scratch

#

same with my lobby system

coral yoke
#

your lobby system?

#

fishnet pro has a example lobby and world

#

do you see it?

#

have you read it?

low minnow
#

i made my own lobby system

#

and scene manager

#

im not using fishnet scene manager

#

im just adding connections to the scenes

#

im not sure im the right person to ask man

placid dune
coral yoke
#

that's cool. i read it hardly.

coral yoke
placid dune
#

The docs should go over those two, otherwise if you have specific questions about them you can definitely ask in a new #1020320683508650025 post or in #🧽help and people will likely be more than happy to assist 🙂

low minnow
coral yoke
low minnow
#

yeah then you're going to have to start a new help post in #🧽help

#

im not using asset bundles

coral yoke
#

i want make lobby and world ,but the sceen is form assetbundles.

#

the example is from buildin.

#

i am working webgl small game on wechat in china.

low minnow
#

@placid dune

#

only the host can ever get past this statement

#

the other clients get stuck here loading into the scene

#

why is that?

#

the clients have fully started the connection here by now

#

so their client manager should be started no?

placid dune
#

I would have thought so. Have you logged the state of ClientManager.Started?

low minnow
#

its never started

#

only the player hosting which started a server first can get past this check

#

all the other clients get stuck here and the rest of the code doesnt continue

placid dune
#

Does the ClientManager.Connection print a valid connection?

low minnow
#

let me check in a minute

low minnow
#

should i check it here?

#

this is where the connection for the client is Started

placid dune
#

Ah that's where you are calling it

#

That's likely too soon

#

Best to use the authentication event

low minnow
#

im using these ones as of right now

placid dune
low minnow
placid dune
#

Once he's connected and authenticated

low minnow
#

so this should be fine?

low minnow
#

because this is how im checking if the server started to then start the client

placid dune
#

The server one should be fine I believe

#

Since the server doesn't need to authenticate itself

low minnow
#

okay

placid dune
low minnow
#

for some reason it still doesnt seem to be working

#

i'll show you where it stops

#

so when im hosting the game and im the server

#

it'll work and load me in perfectly

#

but all the other clients will get stuck here

#

this is the scene manager which gets stuck on line 72

#

wait is it because of these booleans in scene manager?

#

will the OnClientSceneLoaded only run on the server?

#

that might explain why its getting stuck there

#

yup

#

@placid dune

#

the problem is here

#

this only sets true for the host(server)

#

any idea how to fix it?

#

i need another way to check if the connection has been either removed or added

#

and then continue

#

because the broadcasts will only run on the server

#

thats why it never sets those bools on the clients

low minnow
#

let me phrase it differently

#

i need the broadcast to return to the client that called it

#

the boolean to set it true

low minnow
#

any ideas?

placid dune
low minnow
#

smart

low minnow
#

im going to test it out now

#

look correct?

placid dune
#

that looks correct to me

low minnow
#

could you take a quick look please?

#

because once again if im not the host/server, it'll get stuck here

#

the broadcast that i send back is not setting the bool to true

placid dune
#

Can't really see why that may be. You may need to add debug logs to each step to see where it is failing

low minnow
#

these aren't being called

#

for some reason

#

but im sending a broadcast to the server?

#

the clients aren't recieving the returning broadcast

placid dune
#

Ok so if the clients aren't receiving a broadcast it could either mean they aren't yet authenticated (unlikely here), they didn't yet subscribe to receive the broadcast, or the server didn't send it to the correct connection

low minnow
#

so it'll sound dumb

#

i kept forgetting to upload the build with the changes to steam

#

so on my laptop i had the old version instead of the new one

#

it works perfectly

#

my bad

placid dune
#

Ah ok 😁
That's happened to me before too