How to change active scene so update events from multiple scenes always have the proper active scene

This is sort of an extremely specific question. Apologies if it is confusing.

I have two scenes – SceneA and SceneB – running simultaneously in Unity. SceneB is a proxy of SceneA so I will commonly be copying full gameObjects from SceneA to SceneB. The problem is that when any gameObject in SceneB executes Update(), it doesn’t have the correct scene active.

To illustrate the problem, SceneA has a gameObject with a script that contains this code:

private void Update()
{
  Scene activeScene = SceneManager.GetActiveScene();
  Scene myScene = this.gameObject.scene;
  Debug.Log("Active Scene is '" + activeScene.name + "';  This scene is "  + myScene.name);
}

This will output “Active Scene is SceneA; This scene is SceneA”

However, when I copy this gameObject to SceneB, the output will be “Active Scene is SceneA; This scene is SceneB”.

My goal is to have the output be “Active Scene is SceneB; This scene is SceneB”.

Obviously, I could simply write into the code to change the active scene with SceneManager.SetActiveScene(SceneB), but since my goal is to copy any gameObject with any script from SceneA to SceneB, adding this code to every single script is not a feasible.

So it seems like I must have some kind of functionality that senses when the Update() is about to be called in SceneB and change the active scene to SceneB just before Updates() are executed.

I thought I might be able to do this by adding an event to the player loop, maybe by strategically placing a custom event in the loop at the right place. Unfortunately, I do not think this is a solution either. The problem here is that the events of the player loop is interlaced across scenes. For example:

  1. SceneA Update()
  2. SceneB Update()
  3. SceneA LateUpdate()
  4. SceneB LateUpdate()

Furthermore, the execution of these events across gameObjects doesn’t even seem to be grouped by scene, but rather by the order the gameObjects were created at runtime.

  1. SceneA Update() (GameObject1)
  2. SceneB Update() (GameObject2)
  3. SceneA Update() (GameObject3)
  4. SceneA LateUpdate() (GameObject1)
  5. SceneB LateUpdate() (GameObject2)
  6. SceneA LateUpdate() (GameObject3)

How can I reliably manage to change the active scene so that Update() always has the scene that the GameObject lives in to be the active scene without making calls to SceneManager.SetActiveScene(…) in the Update() event inside of every script?

New contributor

Marcus Denke is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật