Skip to content

If a server was started for a 2nd time, NetworkObjectPool doesn't work anymore #733

@AnomalousUnderdog

Description

@AnomalousUnderdog

Describe the bug
I was reading the documentation for Object Pooling since I wanted to add pooled bullet prefabs for my game, and it linked the source code for NetworkObjectPool.cs.

The code looked very strange to me as the pool is initialized only once, then never again. This leads me to believe it won't have correct behaviour if the server is shutdown, then started again for a 2nd time.

I don't know if this is proper Netcode for GameObjects style of coding, but anyway it does give me a KeyNotFoundException when trying to instantiate a pooled prefab when the server is started a 2nd time, because at that point, the _pooledObjects Dictionary has been cleared.

m_HasInitialized is never set back to false when ClearPool is called. Also the existing pooled prefabs don't seem to be cleaned up or reused properly after the server is started for a 2nd time.

I don't get why you have to unregister the prefab handlers anyway upon server shutdown. If the server program is about to exit, then it wouldn't matter since the entire program will close anyway. If the server is merely resetting itself, then wouldn't you want those prefab handlers to still be there?

I'm also confused why this is using its own queue instead of using the already existing ObjectPool class.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: Windows 10
  • Unity Version: 2021.3.10f1
  • BossRoom Version: n/a I got the NetworkObjectPool.cs from a link in the documentation.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stat:backlogStatus - Issue will be addressed in the future.type:bugBug Report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions