Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 JaiCrimson · Aug 30, 2015 at 11:59 AM · referencepositioningenablepersistencedisable object

Have objects persist in one scene, and not across all scenes? (C#)

Hey everyone Jaicrimson here.

I've been trying to figure this out for a while now, and I've come across some really close answers but in the end no cigar.

I am making an rpg, and I would like my player to persist in just one scene. Basically, you run around, bump into an enemy, and a battle starts (like pokemon and trainers or wild grass). The battle takes place through another scene, and after the battle is over, the first scene is reloaded.

Which is the problem.

When I reload the first scene, all positions are reset. The player is spawned back at the starting point, even after having made it through half the level.

I've tried a bunch of different things for this, but I can't even figure out how to turn the players position on the map into a variable/reference. I also can't even get the player object to NOT persist throughout both scene without destroying it.

Right now I have

 void OnTriggerEnter(Collider other){
         if (other.transform.tag == "Battle"){
             nPvt.SetActive(false);
             Application.LoadLevel (1);

which disables the object before the battle scene starts. nPvt is a reference variable to the player's object, I was reading that setting a reference like this could bypass the inspector not being able to find the object after its disabled.

this is the reference variable code.

 void Awake (){
         nPvt = GameObject.Find("newPivot");

And even if I were able to re-enable this object with

 void OnLevelWasLoaded(){
         if(nPvt == isActiveAndEnabled){
             Destroy(GameObject.Find ("newPivot"));
             nPvt.SetActive(true);
             print ("Jet fuel cant melt steel beams");

(disclaimer: I use Destroy because when the level loads, another player object spawns at the start and I destroy that new instance before trying to re-enable the last instance. Not sure how appropriate that is, though.)

then I have no idea if it will even re-enable the object in it's last known position or if it will just respawn it.

I've gotten myself into a bit of a mess here, can any one help out?

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Static object losing references in the Inspector after loading 2 Answers

how can i make it so my blocks switch from grass to log because i have a switch script but i cant make the 2 blocks turn on and off for placing please help 0 Answers

Enable a disabled gameobject via javascript? 1 Answer

What are Keywords and How do I utilise them? 1 Answer

Why does Unity disable the Collider when I Destroy the Rigidbody? (2D) 1 Answer


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