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
0
Question by Jammer3000 · Jun 16, 2014 at 03:55 AM · javascriptmovementarray

Problem with moving objects in array?

Hi the code below gives the error below and I have no idea why? I'm guessing I'm assigning something wrong but I cant seem to find why on any answers or just my own trouble shooting!

Code:

 var coins : GameObject[];
 var trigger = false;
 var target : GameObject;
 var speed : float;
 
 function Start () 
 {
     coins = GameObject.FindGameObjectsWithTag("Coin");
     target = gameObject.transform.position;
     speed = 5.0;
 }
 
 function Update () 
 {
     var step = speed * Time.deltaTime;
     if (trigger == true)
     {
         coins = Vector3.MoveTowards(gameObject.transform.position, target.transform.position, step);
     }
 }

Errors:

 Assets/Scripts/Gameplay Functionality Script.js(75,44): BCE0022: Cannot convert 'UnityEngine.Vector3' to 'UnityEngine.GameObject[]'.

 Assets/Scripts/Gameplay Functionality Script.js(19,39): BCE0022: Cannot convert 'UnityEngine.Vector3' to 'UnityEngine.GameObject'.








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 Clet_ · Jun 16, 2014 at 04:34 AM 1
Share

By troubleshooting, did you at least read the error log? It might look like some incomprehensive bulls**t, but, let's just walk you through what it actually means :

 Assets/Scripts/Gameplay Functionality Script.js(75,44):
 

That means the error is located in the file "Gameplay Functionality Script.js" (with a name like that, it should be an error in itself. Try to avoid spaces in your files/folders name and adding "Script" to a script's name is like if every car were named like "Honda Civic Car" or "Toyota Corolla Car"... redundancy is bad).

Furthermore, it indicates the path to the file, which is in the Scripts folder, under the Asset folder.

Next step, those two little numbers :

 Gameplay Functionality Script.js(75,44)

This comes to say "There is an error at the 44th character on the 75th line in the file Gameplay Functionality Script.js". This is getting obvious no?

Nest stop, the infamous error.

 BCE0022: Cannot convert 'UnityEngine.Vector3' to 'UnityEngine.GameObject[]'

The "BCE0022" is the error code. We don't care much about it because it tells us nothing. BUT, the rest of the sentence... WOW!!! It says that you cannot convert a UnityEngine.Vector3 into a UnityEnigne.GameObject[].

What it means is, you cannot convert a Vector3 to an array of GameObject, which is quite literal isn't it?.

On the 75th line of the Gameplay Functionality Script.js, you are trying to affect a Vecto3 thingy into a GameObject[] thingy and Unity tells you it doesn't understand how to do so, because you can't do it.

Unity does a VERY CLEAR job on pointing out errors, you only have to read them and it will literally (in its figurative sort of meaning) takes you by the hand to bring you to the error.

You can go on and find out what the second error means. (Hint : almost the same s**t).

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by pacific00 · Jun 16, 2014 at 04:19 AM

try

 if (trigger == true)
 {
      for(int k = 0; k <coins.length ; k++ )
      {
         coins[k].transform.position = Vector3.MoveTowards(coins[k].transform.position, target.transform.position, step);
      }
 }

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 Jammer3000 · Jun 18, 2014 at 12:08 AM 0
Share

Any help with the comment I posted under @robertbu???

avatar image
2

Answer by robertbu · Jun 16, 2014 at 04:27 AM

'target' is a GameObject. 'gameObject.transform.position' is a Vector3. So on line 9, you are attempting to assign a Vector3 to a GameObject. You cannot do that. My guess is that you want:

  target.transform.position = gameObject.transform.position;


On line 18, 'coins' is a GameObject[]. Your Vector3.MoveTowards() returns a Vector3. You are trying to assign a Vector3 to an array of game objects. It won't work. Not sure what you are trying to do here. @pacific00 solutions is as good a guess as any.

Comment
Add comment · Show 2 · 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 Jammer3000 · Jun 16, 2014 at 12:59 PM 0
Share

Thank you @robertbu that fixed the first error and @pacific00 fixed the second error but the code still doesn't do anything. I put some debug logs in @pacific00 's code and it will print the first one and the first one in the for loop but not the one after the Vector3.$$anonymous$$oveTowards line of code, so for some reason that line isnt getting hit.

 function Update () 
 {
     var step = speed * Time.deltaTime;
     if (trigger == true)
     {
         Debug.Log("In if, trigger is true");
          for(var k : int = 0; k < coins.length; k++)
          {
              Debug.Log("Before changing coins positiions");
             coins[k].transform.position = Vector3.$$anonymous$$oveTowards(coins[k].transform.position, target.transform.position, step);
             Debug.Log("In for loop, k < coins length");
          }
     }
 }
avatar image Kiwasi · Jun 18, 2014 at 12:32 AM 0
Share

The only way I can see this happening is if Unity has not imported your script properly. Try resaving and reimporting the script.

And please don't post new questions in the 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

23 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Array problem -3 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

How to store aspects (position, name, tag) of a game object in an array to be used for reinstantiation? 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