C# - What script is causing the error?

Is there any reliable way to find out what script could be causing this error? I would like to note how it does not refer to the script in the error:

It does not happen until after the game begins, and I have no idea what could be causing besides that it is a Photon-related error that I cannot locate.

Yes, it tells you in the error. ExitGames.Client.Photon.Protocol16.Serialize. That method is being called by something that has a sprite attached and it can’t be serialized.

I meant what script is causing the error (I found out) but I can’t figure out what could be causing it. What do you mean by attached to a sprite? The script that is causing the error is a Photon script meant to handle the Network-portions of the game but the only references to Sprite it makes is when it reads a custom mod file, grabs a .png from StreamingAssets and converts it into a Sprite.

The error says “cannot serialize() UnityEngine.Sprite” which means that it’s trying to serialize something that has a Sprite attached or referenced by it.

Excuse my ignorance (self-taught programmer so a bit iffy on the technical terms) but what does it mean by serialize? Perhaps if I knew this I could find the problem

Well Photon is a networking plugin, so it’s serializing. This means that it’s creating a transportable representation of your classes. This could be json, xml or binary (or some other thing like msgpack). My guess is that it uses binary serialization, but as an example, let’s say you have this class:

public class Foo
{
    public string Bar { get; set; }
}

Then you create an instance of that class:

var myfoo = new Foo();
myfoo.Bar = "Serialize Me!";

If you serialized that to json you’d get a string that looks like this:

"{ \"Foo\": \"Serialize Me!\"}"

Then you can send that string to a server… save it to a file… whatever… and later you can load it back in and deserializer it (recreate an instance of Foo from that string).

Would you mind taking a look? I think I get the base of what you’re saying but I can’t think about how I would change my code to fix the error. This is the code that is creating the problem (as far as I’m aware because it’s the only part of the code that references Sprites):

[Deleted Code]

Umm… I’m probably the wrong person to ask but:

  1. The variable names are not helpful… I have no idea what they’re doing or for…
  2. Unrelated but you’re setting variablesToSend twice and allocating an unecessary array.
  3. If you’re only expecting to find one match in your foreach, you should “return” inside the end of your “if” block so you stop enumerating the playerList.

This also doesn’t show the actual sending of the information… no idea how that gets done or where, but it looks to me like your “newNotGo” is probably attempting to get serialized by Photon which includes the attached sprite.

FYI, you should post this in the “Scripting” or the “Networking” forums… not General Discussion. You’ll get a better response.

I’ll take your advice, but I threw on a return; at the start of the void and the error is still happening so I guess this isn’t where the error is occurring (so I’m clueless).

Seems to stop when I put a return; on the start void but no references to Sprite are made?

[Deleted Code]

After disabling bunch of components I realize that its not even related to the only script that uses Photon (Makes sense, right?) so fml but this was all useless :c