Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by vuqarahim · Apr 05 at 09:47 PM · animatorscene-loadingscene-switchingdontdestroyonloadreferences

How to keep the same gameobject with different transform values in different scenes

What I am trying to do is the have a trigger object at the end of different levels and when the player gets inside an animation plays, and then the next scene is loaded.

problem is when I add components like animator, when the scene is changed the reference to the component is missing, it is showing in the inspector and in the debug.log, but error log says it is destroyed.

and I cant use dontdestroyonload bc the position of the trigger will be different in all levels.

How can I manage this? Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rh_galaxy · Apr 06 at 01:45 AM

You should do the animation before you load the new scene, at the end of the current scene. You can also have a GameManager set as DontDestroyOnLoad, that keeps the camera and does the animation...

You can have the same prefab Instantiated with different transforms in different scenes, but not the same gameobject. You need to show the code if you want more help.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vuqarahim · Apr 06 at 04:40 PM 0
Share

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class DoorToNextLevel : MonoBehaviour {

 Animator anim;
 PlayerMovement player;


 float t;
 GameObject lift;
 private void Awake()
 {
     lift = Instantiate(GameAssets.Instance.lift, this.transform.position, Quaternion.identity, this.transform);
     player = FindObjectOfType<PlayerMovement>();
     anim = lift.GetComponent<Animator>();
 }

 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.GetComponent<PlayerMovement>())
     {
         EnterLift();
     }

 }

 void EnterLift()
 {
     anim.Play("Lift");
     player.transform.parent = lift.transform;
 }



}

I got it to working, interesting thing is that I was doing this, only difference was that I had a piece of code that referenced PlayerMovement script(it basically made the player go to inside lift when player hit the trigger), and then enter the lift function was called. so that means reference to the player animation was missing? and actually I instantiate the stuff that I want to keep in the scene with additive loading, so I never destroy them, but I think when I parent and deparent player to lift it changes on the scene and the animator gets destroyed because it was in the second scene after I deparent it from the lift which also was in the second scene. it is probably just a order issue on my side. I will fix it.

Which brings to my question, what do you think is the best design pattern to manage scenes?

avatar image rh_galaxy vuqarahim · Apr 06 at 05:12 PM 0
Share

Ok, I didn't get that you load additively. So my answer isn't so useful fore you. But to answer your last question


I have only used scenes in my game like this:
1. GameManager and Camera - Singleton DontDestroyOnLoad (created in Menu-scene when game starts)
2. Menu-scene (normal load)
3. Level-scene (normal load) (win / lose / quit to menu -> repeat from 2)


Now I only play one level at a time, but to pass data from scene to scene I keep data in the GameManager during loading a scene then pass it to the objects in the new scene after load.
So I would not load additively, and let the objects be destroyed when unloaded and then recreated with the properties kept with Instantiate() and an Init() function that I create that takes all properties as parameters.
But there are many ways to do things...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

170 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why do I loose my Animator? 0 Answers

Canvas will only appear on the game screen when its child of a new loaded scene canvas 1 Answer

GUI Elements Carry Over To Next Scene 1 Answer

Multiple EvenetSystems in Scene - only have 1 after searching though 1 Answer

Don't destroy On Load make object not interactable in new scene 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges