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 SeriousNERD · Jun 21, 2016 at 07:57 AM · scripting problemfindobjectsoftype

FindObjectsOfType doesn't find instantiated objects

I'm making a pipe connecting game and I have an object that spawns pipes on click. I have another object(valve) that starts the water and I need this object to find all the pipe connectors. This valve uses FindObjectsOfType and puts them in an array of type connector. This works fine for the objects already in the scene, that is for objects that are there before I start the game. But it doesn't work for pipes I instantiate. This is the code for the valve:

 using UnityEngine;
 using System.Collections;
 
 public class RotirajVentil : MonoBehaviour {
 
     public GameObject izvor;
 
     private int smjer=-1;
     private bool pustiGas = false;
 
     public Veza1[] sveVeze1;
     public Veza2[] sveVeze2;
 
 
     // Use this for initialization
     void Start () {
         sveVeze1= FindObjectsOfType<Veza1> ();
         sveVeze2= FindObjectsOfType<Veza2> ();
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnMouseOver(){
         if(Input.GetMouseButtonDown(1)){
             transform.Rotate(new Vector3(0,0,smjer*90));
             pustiGas = !pustiGas;
             smjer = -smjer;
             Pusti (pustiGas);
         }
 
     }
 
     void Pusti(bool da)
     {
         if(da)
         {
             izvor.GetComponent<ParticleSystem> ().Play ();
             for(int i=0;i<sveVeze1.Length;i++)
             {
                 sveVeze1 [i].pustena = true;
                 sveVeze2 [i].pustena = true;
                 sveVeze1 [i].Pustaj ();
                 sveVeze2 [i].Pustaj ();
             }
         }
         else
         {
             izvor.GetComponent<ParticleSystem> ().Stop ();
             for(int i=0;i<sveVeze1.Length;i++)
             {
                 sveVeze1 [i].pustena = false;
                 sveVeze2 [i].pustena = false;
                 sveVeze1 [i].Pustaj ();
                 sveVeze2 [i].Pustaj ();
             }
         }
 
     }
 }
 

Veza1 and Veza2 ar the connectors of a pipe and are themselves a c#script.

This is the code I instantiate the pipes with:

 using UnityEngine;
 using System.Collections;
 
 public class InstancirajVoduL : MonoBehaviour {
 
     public GameObject VodaL;
 
     // Use this for initialization
     void Start () {
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnMouseOver ()
     {
         if (Input.GetMouseButtonDown (2))
         {
             Instantiate (VodaL, transform.position+(transform.up*-40)+(-transform.forward*10), VodaL.GetComponent<Transform>().rotation);
         }
     }
 }
 

VodaL is the prefab that has Veza1 and Veza2 as its children.

If anyone can help me I would be very grateful.

Comment
Add comment · Show 1
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 SeriousNERD · Jun 20, 2016 at 03:02 PM 1
Share

Solved it. It was stupid, I didin't call the function from update so it couldn't possibly find instantitated objects that appear after creation of the valve.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Script error 1 Answer

Help on scripting a ball 2 Answers

Animation script gravity problem 0 Answers

How would i go about comparing two transform scales 1 Answer

Collision Detecting not working! 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