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
1
Question by Capricornum · Feb 17, 2018 at 12:01 PM · coroutineupdateprofilerinput.mouseposition

[Help] Calling a function, involves another function that is completely unrelated

Dear Community,

I am very confused because in my little project I am calling a function that should not be connected in any way to another (completely unrelated) coroutine. However when I check with the Profiler, apparently that coroutine seems to be involved in the process.

Its like this: On my GridManager Script I am starting a coroutine InitialiseGrid in Start(). So a grid of 8x8 colored pieces is initialized. Then, when I click on one of the colored pieces I am calling a function in my InputManager, that creates a List of equally colored pieces, iterates through them and in their place spawns a little ball with a coroutine on it to move it.

Like this:

 public class GridManager : Monobehavior {
      public Piece piece; //this is a prefab
      private Pieces[,] grid = new Pieces[8, 8];
      private List<Piece> subGrid = new List<Piece>();
 
      void Start {
           StartCoroutine(InitialiseGrid());
      }
      IEnumerator InitialiseGrid {
           for (int c = 0; c < 8; c++) {
                for (int r = 0; r < 8; r++) {
                     Vector2 newPos = new Vector2 (c, r);
                     Piece p = Instantiate (piece, newPos, Quaternion.identity);
                     grid [c, r] = p;
                     yield return null;
                }
           }
      }
      public List<Piece> CollectPieces (Vector2 clickedPos) {
           int x = (int)clickedPos.x;
           int y = (int)clickedPos.y;
           subGrid.Add (grid[x, y]);
           if (x+1 < 8) {
                if (grid [x+1, y].color == grid[x, y].color) {
                     subGrid.Add (grid[x+1, y]);
                }
           }
           return subGrid;
      }
 }
 
 public class InputManager : Monobehavior {
      public Ball ball; //this is a prefab
      public GridManager gridManager;
      private List<Piece> subGrid = new List<Piece>();
 
      void Update ()
      {
           if (Input.MouseButtonDown(0)) {
                //determine Position where clicked. If clickedPos is within grid:
                subGrid = gridManager.CollectPieces(clickedPosition);
               DestroyPieces ();
           }
      }
      void DestroyPieces () {
           foreach (Piece p in subGrid) {
                Ball b = Instantiate (ball, p.transform.position, Quaternion.identity);
                StartCoroutine (b.Ammo());
                Destroy (p.gameObject);
           }
      }
 }

Now when I check with my profiler at the moment where I click the mouse and some pieces get destroyed and some balls go flying, it says:

alt text

So apparently my InitialiseGrid Coroutine seems to be involved when I click. But it shouldn't. Does anybody know what is happening here? I am afraid I might have done something completely wrong. Thank you in advance!!

initialisegrid.jpg (214.5 kB)
initialisegrid.jpg (214.5 kB)
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 Capricornum · Feb 17, 2018 at 04:22 PM 0
Share

Please, does anyone have any idea?

I just realized, that moving the mouse over the screen results in the EventSystem.Update() to do something related to Input$$anonymous$$anger.InitialiseGrid(); Again I see this in the profiler.

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

83 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

Related Questions

Update scene every 5 minutes 2 Answers

How to make a spawner wait for x seconds? 2 Answers

How Stop Update function of other scene 1 Answer

Figuring out Coroutines 3 Answers

Profiler.BeginSample doesn't seem to work in CoRoutine? 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