Ideas on PhotonConverter

jashan
jashan ✭✭
As I was having a bit of trouble with the PhotonConverter I thought I'd start a thread on this tool. First of all, I want to say that I think it's awesome that we have this and I think in general, it does its job quite well. As it's a general purpose tool that should work for most people, the ideas I'm mentioning here are really just that. Some of them might arise from needs very specific to my project.

Breaking Prefab-Connections in Level

That said, just for completeness, as discussed on the Unity forum: Going over and changing the scenes should be done after converting all the prefabs. Reason: The way it's done right now, most if not all prefab connections in the levels are broken which can give you quite a mess. In some cases, it might be easy to fix by just reverting the prefabs - but in some cases that may just not work.

Workaround for "after the fact": My workaround as I've already invested quite a bit of time into the porting: First, using Asset Server, I discarded the changes in most of my scenes (all scenes that use prefabs extensively and apply changes to the prefabs in the level). Then, I added a "if (false) {" in line 56 of PhotonConverter (that's right after the section to convert the scenes which is currently the first thing that's done). I close that block ("}") in line 98, right before "Output(EditorApplication.timeSinceStartup + " Completed conversion!");" ... then run the conversion tool again.

EDIT: You might have to add a check into ConvertNetworkView as well. In my case, I have quite a few objects where for some reason the NetworkView wasn't removed (just seen in ConvertNetworkView that this *should* be the case). So, I've added "if (netView.GetComponent<PhotonView>() == null) {" before "PhotonView view = ..."

Solution (as suggested by Leepo, might even be implemented in the next version): If you haven't done the conversion, yet, you could probably simply move the block that starts with "//Convert NetworkViews to PhotonViews in scenes" right after the block that starts with "//Convert NetworkViews to PhotonViews in Project prefabs" (so that is before "//Convert C#/JS scripts (API stuff)"). That way, you shouldn't have that problem in first place.

Moving Prefabs into Resources-Folders

The Problem: I may have overlooked that in the manual - but I was kind of surprised to see that most of my prefabs were moved into "Resources" folders. In fact, I noticed the problem with this after a longer debugging session that turned out that one of my "configuration scripts" didn't really work anymore, the reason being that it wasn't able to look up on of my configuration prefabs because the path was no longer correct.

I understand the rationale behind this change: Assuming that prefabs need to be instantiated "via the network" by passing the prefab over the network connection by name requires that can be looked up in the resources folder. So, this is needed when you do Network.Instantiate a lot. But: Even then, it's only needed for those prefabs that actually are instantiated over the network. In my case, that would only be 2, maybe 3 or 4 prefabs.

However, I'm not using Network.Instantiate at all because I prefer having full control. So, the way I instantiate objects "over the network" is by sending my own RPC, doing local instantiates and assigning the NetworkViewIDs myself. In other words: In my project, there is not even a single case where I need the prefabs to be in Resources folders.

Idea for a solution: Go through the project and look for "Network.Instantiate". If you don't find it, don't move anything to "Resources" folders at all. If Network.Instantiate is used ... it might be tricky. There's probably ways to figure out what the actual prefabs are that need to be instantiated but that involves a somewhat in-depth analysis of the code and project. Probably, it's easier to just ask the user "Move all prefabs with NetworkViews to resources folders?", and if the user says "no", tell them they'll have to do it themselves.

Comments

  • The next version will have the prefabs fix.
    Furthermore I added a dialog to ask for the Resources/ moving, since that can't be solved much better.