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 mouhammadbatarni · Nov 10, 2018 at 03:36 PM · textunity 2derror messageerror-message

Why is it that whenever i load a new scene while playing some of my linked texts dont work????

Okay, I made a game, in this game I have stores, the stores have texts within them I link these texts using codes such as :

public Text TextObjectName and I link my texts in the game engine, and it all works well and fine, until I load a new scene while playing the game, when that happens the text is not linked anymore, the text does not change and I get an error saying :

MissingReferenceException: The object of type 'Text' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

but if I start my game from that scene it works fine, it is only when I load it while I am playing when I get this error and it doesn't work, which is confusing me a lot, and I don't know what to do.

if you need to know I use the code: SceneManager.LoadScene(SceneNumber); and yes the arrangement of the scenes in the build index is fine and the scene is opening all well except for the texts.

if you know anything about how to solve this please tell me.

EDIT: the texts that are not being linked are texts that are children of a button, I don't know if that helps, but the buttons are also linked in my code, and it also doesn't work, I think it might be the use of public gameobject in the case of the buttons and the public text in the use of the text, is there an alternative way that I can link my objects in a way that when I change scenes they stay linked???

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
Best Answer

Answer by ecv80 · Nov 19, 2018 at 09:01 AM

Object.DontDestroyOnLoad

You probably want to call that in the Awake/Start part of some script using a reference to the root GameObject (such as Canvas) holding your Texts as children, in order to preserve them across different scenes.

 void Start() {
    DontDestroyOnLoad(GameObject.Find("Canvas"));
 }

Original answer: You probably want to call that in the Awake/Start part of some of your script where you have a reference to your Texts, in order to preserve them across different scenes.

Comment
Add comment · Show 4 · 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 mouhammadbatarni · Nov 19, 2018 at 10:09 AM 0
Share

it didn't work but I got this message:

DontDestroyOnLoad only work for root GameObjects or components on root GameObjects. UnityEngine.Object:DontDestroyOnLoad(Object) Store:Start() (at Assets/Scripts/Store.cs:515)

do you know why?

avatar image ecv80 mouhammadbatarni · Nov 19, 2018 at 12:30 PM 0
Share

I don't really know, but I suspect the GameObjects in question need to be at the root of your hierarchy. $$anonymous$$inda makes sense... Since you're most likely using Text somewhere within your Canvas tree, you might want to try to preserve the full canvas by calling DontDestroyOnLoad on it ins$$anonymous$$d of simply on the Text GOs. Tell me how it goes.

avatar image mouhammadbatarni ecv80 · Nov 19, 2018 at 05:52 PM 0
Share

i guess it worked, now all the buttons are working and the game is functioning, but i use playerprefs to load some data, and not everything is loading correctly moving scene to scene, but ill figure this one on my own, thank you very much for your help

Show more comments

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

102 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

Related Questions

Rpg creator kit doesnt work? 1 Answer

unity2d text UI is appearing above my loading prefab 0 Answers

im getting this error: NullReferenceException: Object reference not set to an instance of an object Item.Start () (at Assets/Scripts/Inventory System/Item.js:9) 1 Answer

google play services build error 0 Answers

Error While Build APK Signed,Error while build APK Signed. 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