Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Aug 04, 2020 at 04:37 PM by dwittsac for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by dwittsac · Aug 03, 2020 at 12:44 AM · noobsetactiveconfused

SetActive doesn't work from .exe

I have a little program that asks multiple choice trivia questions. I want to be able to display and hide those questions and answers. It works in Unity... but not when compiled.

I have a GameController that holds a reference to a QuestionAnswerGroup GameObject that I want to sometimes be active and sometimes not be active. This works great when I am running the game in Unity, but when I build it and compile to an exe and run the game from there, things work totally differently. It never reactivates the group when it should. It will go from active to inactive but never back the other way. Only in the compiled code though. Like I said, when debugging in Unity it toggles on and off just great.

Does anyone have any idea what's happening here?

Here's a bit of my code:

In controller:

 public void GetAndDisplayNewTriviaQuestion(string color)
     {       
          var questionDisplay = new QuestionDisplay();
         _currentQuestion = questionDisplay.GetNewQuestion(color, _qdb);
         ActivateQuestionAnswerGroup(true);      
         questionDisplay.DisplayQuestion(_currentQuestion);
     }
 
  public void ActivateQuestionAnswerGroup(bool setActive)
     {
         _questionAnswerGroup.SetActive(setActive);
     }

In a different script attached to a Button, call to deactivate (answerSelected is called OnClick):

 public void AnswerSelected()
     {
         var rc = FindObjectOfType<RuleController>();
         rc.CheckAnswer(this.GetComponentInChildren<Text>().text);
         rc.ActivateQuestionAnswerGroup(false);
     }


Comment
Add comment · Show 8
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 dwittsac · Aug 03, 2020 at 12:45 AM 0
Share

Oh dear, the code formatting did not keep at all... so sorry.

avatar image Elango · Aug 03, 2020 at 05:39 AM 1
Share

Are you sure you copied the code correctly? Because

 FindObjectOfType();

is not a valid method call. It won't even compile / build. It's actually better not to use it at all, Find by Type is very slow.

avatar image dwittsac Elango · Aug 03, 2020 at 01:11 PM 0
Share

Yeah, it seems anything inside of angled brackets didn't make it into the code I pasted. It should have the RuleController type specified. FindObjectOfType<'RuleController'>() This program is the first thing I've written using Unity, so most of what I'm using (such as FindObjectOfType) are from suggestions I found online. Is there another function you'd recommend for locating GameObjects?

avatar image Elango dwittsac · Aug 03, 2020 at 10:29 PM 1
Share

Check Player log for errors (like UnassignedReferenceException): https://docs.unity3d.com/$$anonymous$$anual/LogFiles.html Put Debug.Log into GetAndDisplayNewTriviaQuestion and ActivateQuestionAnswerGroup to check each variable for null. Are you using Find elsewhere? It's only returns active objects. Also deactivating object will stop it's Update's and coroutines. And if you deactivate parent then you won't be able to activate child. If direct assignment is not possible then the best option from Find is FindWithTag. Alternatively, you can use a singleton.

Show more comments

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by dwittsac · Aug 04, 2020 at 04:36 PM

Thank you to @Elango and @davidcox70 The issue was in fact that the CSV file couldn't be located because: "When Unity compiles, it only includes the files that it needs to build scenes plus everything it finds in the Assets/Resources folder. So if your CSV file is not in Assets/Resources, it will not make it to the build and that might be were your problem is ultimately to be found."

Resolution was to move the file to Assets/Resources and use Resources.Load()

Thanks!

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

138 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

Related Questions

physics.OverlapSphere colliders 1 Answer

I want to rotate my character 90 degrees but set the value of the rotation to 0 1 Answer

how do you make an interactive pause menu? 1 Answer

So I'm trying to like make a game in which an gameobject with a certain tag gains health if they collide with another gameobject with the tag such as "healthCube" 0 Answers

Unable to reactive the game object 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