FirstGearGames / FishNet

FishNet: Unity Networking Evolved.
Other
1.4k stars 150 forks source link

Multiple Nested Prefab Can Cause Errors That Happen At Startup of Game That Doesn't Allow Fishnet to work after Initial Startup. #631

Open Katerlad opened 8 months ago

Katerlad commented 8 months ago

General Unity version: Fish-Networking version: 3.11.18 Discord link: https://discord.com/channels/424284635074134018/1223395408743497791 ** Above, post a link from our Discord where you troubleshot the issue (on Discord click the three dots next to the message, then Copy Message Link). Issue may be closed out if this is not included.

Description A clear and concise description of what the bug is.

Please Read Carefully, this isn't

just the spamming of the tryAddComponent Warning, there is something bigger at play here.

When Creating Nested Prefabs with Network Behaviors on the prefab, the NetworkManager can get in a state where it AssetHashPath Errors occur and NetworkManager Becomes null on game startup.

Replication Steps to reproduce the behavior:

There are a couple different ways to get it into this state, but here is the way I found works the most. To Reproduce

  1. Create Parent Prefab in your project and Open it.
  2. Add Empty Network Behaviour.
  3. Create Child Object inside the prefab. (Do not make it a prefab yet)
  4. Add a Empty Network Behaviour to it.
  5. Create a SubChild Object (Do not make it a prefab yet)
  6. Add Empty Network Behaviour to it.
  7. Create a Second SubChild Object under "Child" object ( Do not make it a prefab yet)
  8. Add a Empty Network Behaviour to it.
  9. Drag SubChild Object into your project, (This makes it a prefab)
  10. Notice your cursor starts spinning and glitching. (This I believe is Fishnet trying to add a Network Object to the Prefab but failing) Spaming the TryAddComponent Warning.
  11. Drag SubChild2 Object into your project (This makes it a prefab)
  12. This also makes your cursor spin and glitch.
  13. Drag Child Object into project ( This makes this a prefab with 2 subchild Prefabs beneath it.
  14. Start game, only 1 AssetHashPath Error will appear.
  15. Open Each Prefab in your project by double clicking it (Parent, Child, SubChild, and SubChild2)
  16. Try running game agian.
  17. Notice errors, and NetworkManager Null Error, causing Fishnet not to work in Game.
    • This is where game gets into a state that you have to fix the prefabs problem but It is not easily fixable you cannot just remove the Network Object in the prefabs so fishnet can just regenerate them. Like other people with just the Spamming of the warning.

You have to remove the network behavior itself and read it, and imagine having to do that on a bigger project where you have varioables all set up ( Thats what we had to do)

Expected behavior I expect to be able to add and remove Nested Prefabs to a Prefab and fishnet gracefully handle any use case thats thrown at it. Cleaning up the game object properly if possible without Unity Limitations.

Game Build Files See Build File Below to see Issue in action ChildPrefabBug.zip

Katerlad commented 8 months ago

If this is such a small use case that it gets passed off, I can see that, however... I ran into it and it took hours of my day to figure it out, which pissed me off enough to deep dive into it so others who may build prefabs like me do not run into similar problems.

FirstGearGames commented 8 months ago

Do you know if this happens in V4? If not, going to mark this as wont fix.

Katerlad commented 8 months ago

I'll load up the example project and upgrade to 4 and see. Give me like 1 hour.

Katerlad commented 8 months ago

Yes doing the same steps as above in that exact order causes the problem in 4.1.6.

It just seems like there is some cleanup and checks that need to be done on the fishnet side, when a prefab is being created from a child of another prefab.

I Know some people run into the the initial warning all the time, but after removing the network object and let fishnet auto reapply it, the problem goes away.

If you do more things while the problem exists, then you get stuck in this state where everything is corrupt and you have to remove the Network Behavior. Luckily I did test that you can copy component values, and paste them so you don't lost all your preset variables.

But if there is a way for Fishnet to more gracefully handle these prefab scenarios, less people will have to bump into these small snags that add up.

Again though, there may be some unity limitation that is why this is happening and there isnt, anything you can do but IDK if you've really looked into it either ;)

FirstGearGames commented 8 months ago

Marked a bug, low priority for now.

makcimbx commented 8 months ago

For me, i commented automatically add NetworkObject line in TryAddNetworkObject method from NetworkBehaviour, that make prefab broken, so i do everything manual. image Also i add button, for prefab regenerate nested network objects, that also helps. image After this, everything almost always works well.

FirstGearGames commented 2 months ago

Is this still an issue @Katerlad ? That system got a big rework recently.

FirstGearGames commented 1 month ago

Queued to close in 2 weeks if there is no new activity.

Katerlad commented 1 month ago

I unfortunately do not have the time to test this out, I did see that someone commented on the priority help post I made in discord with the same issue asking if this is going to be fixed. Not sure if he was running into the same exact problem or not. Here is the link to the discord post where the other user mentioned he had the same problem.

https://discord.com/channels/424284635074134018/1223395408743497791

FirstGearGames commented 1 month ago

No worries. I'll get to it eventually.