PhotonNetwork.Instantiate doesn't work with no errors
Options
Hi, I've got a bit of a problem. I'm making a multiplayer map maker and testing it with your friends is a big part of it, as it actually allow you to interact with the map. How I do it is:
I PhotonNetwork.Destroy() the level editor player (The one editing the level)
PhotonNetwork.Instantiate() the testing player
I'm instantiating the testing player in the same way i instantiate the level editor player, and for some reason it doesnt do it if you aren't the master client. But if I run the game twice on my local machine, it works. If you arent the master client it simply doesnt instantiate it, with no error at all. Here's my code, I'm not sure whats wrong:
I PhotonNetwork.Destroy() the level editor player (The one editing the level)
PhotonNetwork.Instantiate() the testing player
I'm instantiating the testing player in the same way i instantiate the level editor player, and for some reason it doesnt do it if you aren't the master client. But if I run the game twice on my local machine, it works. If you arent the master client it simply doesnt instantiate it, with no error at all. Here's my code, I'm not sure whats wrong:
Destroy(playerInstance.GetComponent<Building>().VisualizerInstance); //Destroy the hologram for where the object is gonna go PhotonNetwork.Destroy(playerInstance.gameObject); //Destroy the Level editor player isTesting = true; //sets isTesting to true builderUI.SetActive(false); //Disables the level editors UI TesterUI.SetActive(true); //Enables the testers UI if (encryptor.GameMode == "FPS") //If were making an FPS map { print("Instantiating shooter"); playerInstance = PhotonNetwork.Instantiate(shooter.name, spawnPoint.position, spawnPoint.rotation, 0); //Instantiate the shooter print("Instantiated!"); }I have no clue whats happening. Thanks in advance.
0
Best Answer
-
Well. If the Log() did not show up anywhere, it may mean that this code is not running.
You don't need actual error messages to debug any situation. You can set a breakpoint in the code, attach the IDE to Unity and just run it step by step. Verify that each line of code runs as expected and that the message gets sent.
The client will timeout but you can stop and run the situation another time with a breakpoint where you'd expect the receiver to run the code...
There are a lot of good tutorials on debugging and using breakpoints online. A powerful tool to learn.
5
Answers
-
The only change I've made to Photon's code is changing the Destroy() function so that you can remove other builders blocks.0
-
I got my friend to test it by running it twice, and the master client thing happens on his pc. But on my pc, both can test?0
-
Bump0
-
Bump again0
-
Anyone? Please? I've worked so hard on this project and I don't want to end up abandoning it due to this error.0
-
Bump again0
-
It worked perfectly fine until I added the script that disables other scripts depending on isMine. But what's weird is that the script works for the level editor player, despite the fact that they are both built similarly0
-
Bump again, I'm not sure why I'm not getting any help0
-
Bump0
-
can someone PLEASE help, for some reason it feels like people want to ignore me and just leave my game to fail. Do you guys recognize my name or something? Just someone please help.0
-
Bump0
-
Bump0
-
Bump0
-
Please don't bump within hours.
We'll have a look when we got the time.0 -
Update: The provided info is not enough. You have to debug this to a degree that we can understand what is going on in the background.
If you modified PUN, we can't support that properly either.
Any player may instantiate a networked object. You may want to debug your changed code and make sure the Instantiate runs, gets sent and received...0 -
Ive tried to debug it, but i can't as theres no actual error or anything coming from it0
-
I do remember putting a print("Instantiating Player...") before he's instantiated, but even that didnt work0
-
Well. If the Log() did not show up anywhere, it may mean that this code is not running.
You don't need actual error messages to debug any situation. You can set a breakpoint in the code, attach the IDE to Unity and just run it step by step. Verify that each line of code runs as expected and that the message gets sent.
The client will timeout but you can stop and run the situation another time with a breakpoint where you'd expect the receiver to run the code...
There are a lot of good tutorials on debugging and using breakpoints online. A powerful tool to learn.
5 -
Turns out that for some reason the if statement wasn't running. I don't know why, but the second it hit the if statement it bricked itself0