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 /
avatar image
1
Question by Reeceg · May 07, 2015 at 02:25 AM · c#updateonce

c# void Update() is only working once

This code\/ is supposed to make mesh and update the vertices every frame but it doesn't so I put a test var and in update made it test += 1; but it only counts to 1 so update is only called once for some reason.

  void Update()
         {
             GetComponent<MeshFilter>().mesh = CrateMeshChunk();
             GetComponent<MeshCollider>().mesh = CrateMeshChunk();
         }
     Mesh CrateMeshChunk()
         {    
               V1 = transform.InverseTransformPoint(Me.transform.position);
              V2 = transform.InverseTransformPoint(NeighbourTop.transform.position);
              V3 = transform.InverseTransformPoint(NeighbourLeft.transform.position);
             V4 = transform.InverseTransformPoint(NeighbourLeft.GetComponent<Neighbour>().NeighbourTop.transform.position);
     
             Mesh mesh = new Mesh();
     
              Vector3[] vertices = new Vector3[]
              {
                  V1,V2,V3,V4,
              };
      
              Vector2[] uv = new Vector2[]
              {
                 UV1,UV2,UV3,UV4,
              };
          
              int[] triangles = new int[]
              {
                  0, 1, 2,
                  2, 1, 3,
              };
          
              mesh.vertices = vertices;
              mesh.uv = uv;
              mesh.triangles = triangles;
          
              return mesh;
          }







Comment
Add comment · Show 11
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 Catlard · May 07, 2015 at 04:33 AM 0
Share

Does another script in your project also update as expected? Does this class inherit from monobehavior? If so, then there's something wrong with your updating.

avatar image Reeceg Catlard · May 07, 2015 at 04:41 AM 0
Share

Its for all scripts and they do inherit monobehavior.

avatar image Catlard Catlard · May 07, 2015 at 05:32 AM 0
Share

Put another script in the same scene, and see if it updates correctly. Does it? is this the only script that does not Update? If so, what is different about this script? The way to solve this is to continue commenting out parts of this script you've posted until you find a version that updates correctly -- then you'll find your problem, I think.

avatar image Catlard · May 07, 2015 at 05:49 AM 0
Share

Ok, fair enough, but now how am I supposed to get credit for answering your question?

avatar image Reeceg · May 07, 2015 at 05:59 AM 1
Share

I made this script and it only goes to 1.

 using UnityEngine;
 using System.Collections;
 public class Test : $$anonymous$$onoBehaviour
 {
     public int test;
 
     void Update ()
     {
         test += 1;
     }
 }



avatar image fafase · May 07, 2015 at 06:39 AM 0
Share

So make sure first before anything else, that the GameObject is active, that the component is not being removed/destroyed and that it is active.

Once we know of that, we can go further.

avatar image Reeceg · May 07, 2015 at 06:41 AM 0
Share

The GameObject is active. The component is not being removed and it is active.

Show more comments

1 Reply

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

Answer by Catlard · May 07, 2015 at 06:13 AM

The script in the comment above works in my editor -- it updates test, and the number gets higher than 1. I suspect that your editor preferences have become weird, or something. My advice is to either reset your unity to the default settings and see if this still happens, or reinstall Unity.

EDIT: You could also try putting your script in a new project. If it works in the new project, then you could try reimporting all assets. If it doesn't work in a fresh project, then your copy of Unity is broken. If it does work in a new project, I suspect your project is broken somehow, and you could try migrating things from your old project until you find the broken bit.

EDIT 2: Had a look at your project. The problem was that your program was crashing on these lines:

 V1 = transform.InverseTransformPoint(Me.transform.position);
          V2 = transform.InverseTransformPoint(NeighbourTop.transform.position);
          V3 = transform.InverseTransformPoint(NeighbourLeft.transform.position);
         V4 = transform.InverseTransformPoint(NeighbourLeft.GetComponent<Neighbour>().NeighbourTop.transform.position);


It was crashing there because none of the "Neighbor" objects were assigned at that point, so it crashed the program and the editor paused. The reason it paused is because your "console" window had "Error Pause" checked.

Was this the problem?

Also, consider parenting your Voxels to the object that created them when you instantiate them, to keep your hierarchy tidy.

Comment
Add comment · Show 10 · 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 Reeceg · May 07, 2015 at 06:16 AM 1
Share

How do I reset? I haven't changed anything recently.

avatar image Reeceg · May 07, 2015 at 06:19 AM 1
Share

I there a way to pause the scene in code because I think thats what it's doing.

avatar image Catlard · May 07, 2015 at 06:21 AM 0
Share

I would just redownload it. There's no way to pause the editor from code unless you're running an editor script, which I suspect you are not.

Also this:

http://askubuntu.com/questions/17610/how-do-i-reset-my-unity-configuration

avatar image Reeceg · May 07, 2015 at 06:27 AM 1
Share

$$anonymous$$y internet doesn't recap for a week so redownloading's not an option right now. No Im not using an editor script but I used // to hide the GetComponent<$$anonymous$$eshFilter>().mesh = Crate$$anonymous$$eshChunk(); GetComponent<$$anonymous$$eshCollider>().mesh = Crate$$anonymous$$eshChunk(); and it dosn't pause now so something in $$anonymous$$esh Crate$$anonymous$$eshChunk() is pausing the scene.

avatar image Catlard · May 07, 2015 at 06:40 AM 0
Share

Edited comment. Updated answer.

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

20 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

Related Questions

Calling a method once in update 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Pause Menu Text Not Rendering 0 Answers

Is there a way to prevent the use of Update/FixedUpdate in child scripts? 2 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