Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 Jacobsc · Dec 14, 2019 at 06:59 PM · prefabprefabsprefab-instanceprefab changing at runtimeprefab connection

Prefabs won't change?

So I'm trying to make all of my prefabs to turn off their renderers and others turn into triggers, but the prefab changes but the in-game objects linked to the prefab does not. Here are some lines that are related:

 public GameObject m_GreenDoor;
 public GameObject m_RedDoor;
 public GameObject m_GreenCube;
 public GameObject m_RedCube;
 void OnTriggerEnter(Collider other)
 {
     //green
     if (other.gameObject.tag == "GreenCube")
     {
         m_GreenCube.GetComponent<Renderer>().enabled = false;
         m_RedCube.GetComponent<Renderer>().enabled = true;
         isGreen = true;
         ChangeColor();
     }
     //red
     if (other.gameObject.tag == "RedCube")
     {
         m_RedCube.GetComponent<Renderer>().enabled = false;
         m_GreenCube.GetComponent<Renderer>().enabled = true;
         isRed = true;
         ChangeColor();
     }
 }
 public void OpenDoor()
 {
     if (isGreen == true)
     {
         m_GreenDoor.GetComponent<Collider>().isTrigger = false;
     }
     if (isRed == true)
     {
         m_RedDoor.GetComponent<Collider>().isTrigger = false;
     }
 }

I have just realized another issue, if I collect green (turns ship green), then red (turns ship red) I can't turn back to green. If you have some input that would be helpful.

Comment
Add comment · Show 3
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 leftshoe18 · Dec 15, 2019 at 02:32 AM 0
Share

What does the ChangeColor() function do? If it's changing the other's tag then you might have an issue with the second if condition firing. I'd change that to an "else if" and see if that helps.

As far as your main issue goes, you are just changing the prefabs themselves which is why things in the scene aren't changing. At runtime all prefabs are uncoupled from their source prefab I think. You might want to grab a list or array of all green doors, green cubes, etc. at the beginning of the scene or something and iterate through that as needed.

avatar image Jacobsc leftshoe18 · Dec 15, 2019 at 04:19 AM 0
Share

Oh, that changes the color of the character, I should have removed those to make it clear. Those aren't related. Sorry about that. The goal is to hide the cube by turning the renderer off until a new cube is collected. Also is there an easier way to do this other than just listing every cube type? (there will be more later). This is my first game so I'm going with a simple color swap game.

avatar image Jacobsc · Dec 15, 2019 at 05:05 AM 0
Share

Ok so the script it kinda working, I left for an hour and the red cube's renderer turned off with the game off. Then I tried to fix it but ended up doing nothing but did a test for fun. I then came back and an hour later and the green cube's renderer turned off. I am really confused on what is going on.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ThomasOr · Dec 15, 2019 at 11:00 AM

You shouldn't be making changes via the prefab system, that can fork up your game. Instead you should use FindWithTag or some other GameObject.find to get every instance of your prefab and then a foreach loop to iterate your changes over them.

I suspect that you actually don't have multiple of the same instance of a prefab however, so you should just drag and drop the in-scene objects to the gameObject slots and not the root prefabs. You should only use the root prefabs when you will be instantiating it at least one time which you are not.

Comment
Add comment · Show 1 · 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 Jacobsc · Dec 16, 2019 at 02:21 AM 0
Share

Well currently I only have one gameObject, but when I add more levels I will need to change many Objects at the same time. But it works now, thanks!

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

156 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

Related Questions

Unity Programmatically Link Prefab 2 Answers

Some components missing in the prefab (clone) 0 Answers

Changing the variable 'power' of ONE turret instead of ALL turrets 1 Answer

Prefabs instantiated at runtime disappear right after 0 Answers

prefab navagent doesnt work,prefab navmesh doesnt work 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