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

Additive Scenes #1

Open
mbbmbbmm opened this issue Feb 6, 2017 · 3 comments
Open

Additive Scenes #1

mbbmbbmm opened this issue Feb 6, 2017 · 3 comments
Assignees

Comments

@mbbmbbmm
Copy link

mbbmbbmm commented Feb 6, 2017

Hi!
I am using UnityTimer in the context of additive scenes. I have a main scene as a kind of manager scene that is never unloaded, but it cannot be the active scene most of the time. It needs to hold the TimerManager because the other scenes are all volatile. My workaround for now was to spawn a dummy timer at startup in the main scene and setting it to loop so it will always be there.

Would it be OK to make the TimerManager class public instead and add it manually from a different script in the main scene?

void Start()
{
    GameObject managerObject = new GameObject { name = "TimerManager" };
    managerObject.AddComponent<Timer.TimerManager>();
}

I made a little test and it seems to work, but I am not sure if there are going to be problems if TimerManager is public.

Thanks!
Jan

@akbiggs akbiggs self-assigned this Feb 6, 2017
@akbiggs
Copy link
Owner

akbiggs commented Feb 6, 2017

Hey Jan! This is a really good point, thanks for the issue.

My main reason for not wanting to make TimerManager public is just that I don't want people to have to worry about managing it - ideally it would take care of spawning itself when you call Timer.Register for the first time, in a way that just works, so you don't have to worry about calling Timer.Register only after the TimerManager has been created.

I'm not too experienced with additive scenes -- would it make sense for us to change the TimerManager spawning logic so it gets spawned into its own separate scene?

@akbiggs
Copy link
Owner

akbiggs commented Feb 6, 2017

That way the TimerManager won't be created inside one of the volatile scenes.

@mbbmbbmm
Copy link
Author

mbbmbbmm commented Feb 7, 2017

So with additive scenes there's always one active scene, by default it is the last loaded scene. As far as I know the active scene is responsible for two things: it's the scene where GameObjects are instantiated, and it is the scene that provides the main data for the lighting.

This second responsibility is what makes it a little less easy than it probably should be :)

I haven't tried to create scenes at runtime yet, and I don't know if they get activated by default. It may be necessary to prevent that so the GI never gets switched and other instantiated GameObjects would appear in the correct scene.
Also it would be important to protect the created scene from accidentally being unloaded, which may be problematic too...

I know that it's possible to instantiate GameObjects in inactive scenes by using a parent, i.e. searching the desired parent with "GameObject.Find" and then using that reference.

Maybe the easiest thing would be to have an optional script or prefab for users who use additive scenes.
I think everybody who uses them is aware of the additional set up required to make them work.
So e.g. if there's a GameObject called TimerManager placed by the Unity user in one of the loaded scenes use that and add the TimerManager class automatically.

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

2 participants