Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VContainer and Netcode for GameObjects #751

Open
BoltBlasterLuk opened this issue Feb 13, 2025 · 0 comments
Open

VContainer and Netcode for GameObjects #751

BoltBlasterLuk opened this issue Feb 13, 2025 · 0 comments

Comments

@BoltBlasterLuk
Copy link

Hi there,

First of all, thanks for writing VContainer, we recently started using this in our game and it's a real lifesaver. There's just one issue I'd like your opinion on, we also use Unity's Netcode for GameObjects. We have several enemies that get spawned dynamically during a run. These Enemy NetworkObjects get synced over the network (by using the NetworkManager.SpawnManager). Both client and server have a LifetimeScope GameObject in the scene with the same set of registrations. Obviously I don't want to inject the dependencies on the server and send it serialized to the clients (that would definitely bring a world of hurt). I ended up with a solution where every dynamically created NetworkBehaviour has a line in its Awake method to tell VContainer to inject itself. Like so:

private void Awake()
{
    GameLifetimeScope.Container.Inject(this);
}

This still feels kind of icky, because the GameLifetimeScope is now a Singleton that lives outside of the whole Dependency Injection framework (because I can't get an instance of the IObjectResolver any other way).
I also looked at Unity's Boss Room (https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop) example which uses VContainer in combination with Netcode for GameObjects. Which also doesn't really solve the issue in a very clean way. Do you have any thoughts or suggestions on the topic?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant