-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
OnEnable/OnDisable #330
Comments
Also of note this was found while converting a Mirror based project over to MirrorNG. Aside from small renames and refactors no changes to NG core were made. This issue seems to be based on features/timing of Mirror and differences in NG. I am not great at object/sync stuff but an idea that came to mind would be adding an OnEnable/OnDisable style event to NetworkIdentity. I have not yet tested if the StartClient and StartServer events satisfy the timing of this issue. |
I was able to confirm the issue via tests and confirmed a potential solution/workaround
|
Won't work in pool objects where things are disabled and enabled for pooling
…On Mon., Aug. 3, 2020, 8:52 p.m. uwee, ***@***.***> wrote:
I was able to confirm the issue via tests and confirmed a potential
solution/workaround
public class SampleBehavior : NetworkBehaviour
{
public void Start()
{
NetIdentity.OnStartServer.AddListener(Enable);
}
public void Enable()
{
//All Tests Pass
if(Server.Active) { }
}
public void OnEnable()
{
//All Tests Fail
if (Server.Active) { }
}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#330 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC2BKVKLXUMISSBIWTV3SX3R65LWRANCNFSM4PTQCH3A>
.
|
This is by design. The object may be instantiated in the server and never spawned. There may also be multiple servers, so until an object is spawned, there is no way to know which Server or Client it will be used in. If you need to initialize something when the object is networked, then subscribe to NetIdentity.OnStartServer or NetIdentity.OnStartClient and initialize your object there instead. |
Can we close this? Is there going to be a revisit? Does it need to be written in documentation? |
Describe the bug
Since going to events. Most events usually sit in OnEnable / OnDisable. Thats where i put most of the events to tap into for OnStartServer or OnStartClient etc. Some of the objects like my bullets and smooth sync seem to not like it. It randomly at times fires the OnEnable before Server is set inside of the NetworkBehaviour.
Repro project
My Project is huge. I will try to setup something with examples.
To Reproduce
Place a Server.Active check inside of OnEnable of a NetworkBehaviour script of an object being spawned in. It will give errors.
Expected behavior
Expected behaviour would be to have the setting of variables way before OnEnable and OnDisable ever fires off like in awake or Start. Im not sure how or where the Server variable gets set inside of NetworkIdentity.
Screenshots
@uweenukr Was helping me and saw most of my screenshots if need be I can take more.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: