[Netcode/MLAPI] network object being visible across scenes
Hi guys just a quick question concerning Netcode for those that know.
My player has network object and network transform attached to them. I attached a script to give the player the property of dontdestroyonload() and I have the option to load the player into another scene/map via a "portal" which is basically a gameobject with a boxcollider2d to detect ontriggerenter events.
What I realized now is that a network object exists across the whole server and hence is not dependent on the scene.
What this means is that player A in scene A can see player B in scene B and vice versa which is not the intended effect. Has anyone come across this particular situation or would like to share a solution to this?
I hope the attached screenshot better clarifies my situation
Answer by VanToRiaXVII · Apr 25 at 03:23 PM
From what I understand, you don't want the other player to appear once they have teleported to another scene. There are different ways to do that depending on the specific concept of your game.
The easiest way would be to make the other player invisible once he teleports to another scene. You would still receive information about this player, but the client won't see it.
The better, but more complex way, of doing it would be to destroy the network object of the other player when they teleport and add it back when the two players are on the same scene.
I've considered this but it would not work for my case as one user may login to the game in scene A and the other may login to scene B. Can't invoke a destroy when switching scene as they already exist upon logging in and they are already supposed to be in different scenes. Thanks for the suggestion though
I'm not very familiar with MLAPI, but my guess would be to assign the network object to a specific scene so all the objects in scene B, including the player, don't get rendered while you display scene A with its associated player.
Now, DontDestroyOnLoad is a function that allows you to keep an object when changing scenes. So, perhaps, this is not what you should be using because it's keeping a reference to the other player, even when they change scenes.
Yup that's the part where I need to find out if it's possible to assign a network object to a particular scene.
As for your concern with dontdestroyonload I can't believe I didn't consider that lol but I got a fix for that immediately, for MLAPI you can detect if the client is the local player. If so then just dontdestroyonload else leave it alone and it will destroy when changing scene.
Your answer
Follow this Question
Related Questions
Networking Pushing 0 Answers
Why is my script firing 2 bullets on the client side? 0 Answers
"failed to spawn server object" error. 1 Answer
Multiplayer - Host and Client problem with input. 1 Answer
Floating Point Error? 1 Answer