Hints for Netcode for Gameobjects + VContainer | Missing injection in network objects #745
ModischFabrications
started this conversation in
General
Replies: 1 comment
-
|
My solution here is: the lifetime scope that should inject dynamically generated objects do not directly inherit from |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This might be interesting for the wiki and/or readme as well, feel free to move if so. I have stumbled a few times already looking for hints on Netcode for Gameobjects (NGO) + VContainer. This is my attempt to help newcomers like me.
Problem
Dynamically network/client-side spawned gameobjects will not have any injection, because they are instantiated by the networking solution of NGO.
Solution
Find the container and request injection manually.
#357 has a basic version for this, but
GetComponentInParentwill rarely work for network-spawned objects, because client-side spawned objects are usually in the root instead of being a child of the scope.FindAnyObjectByType<LifetimeScope>()is a naive alternative, but will find scopes from other scenes, which could be a problem for bootstrapped ones.I found two options that are valid for me and did some simple benchmarks in the editor:
Option A (x100) (works only if the scope is a root objects in the scene, which it usually is for me)
Option B (x100)
=> In summary: Search in root components if you have the option, look everywhere if you need more safety. Both should be fine to run every once in a while. Try not to do this every frame, it's expensive!
Beta Was this translation helpful? Give feedback.
All reactions