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 piko · Jun 07, 2012 at 07:43 AM · errortransformidentifierunknown

BCE0005: Unknown identifier: 'transform'

I have looked around to find an answer to my problem but have not come across any, so I'm sorry if I did overlook it. My script was working in the previous versions of Unity but ever since I did a recent update (I've been absent for a while) a lot of scripts have errors written all over them. Here is the script...

 //class that defines the physical properties and attributes of the cannonball
 class cannonBlast {
     var cannonball : GameObject;            //create a slot to assign the cannonball prefab to
     var blastParticle : ParticleEmitter;    //create a blast particle slot to assign a particle emitter
     var cannonLight : Light;                //create a light slot to assign a light prefab for when the blast occurs
     var spawnPos : Transform;                //create a slot to assign an empty game object as the point to spawn the cannon
     var shooting : boolean = false;            //a boolean we can use to stop the player from shooting during the actual shot
 }

 var cannon : cannonBlast;                    //a varible used to access all other variables inside of the connected class (essentially a group)

 //class that defines the mechanics of the cannonball
 class cannonballMechanics {
     var fireRate : float = 0.5;                //a variable setting the rate of fire
     var reloadRate : float = 1.5;            //a variable setting the time for reload
     var force : int = 1000;                    //the cannons maximum power
 
     @System.NonSerialized
     var nextFire : float = 0.0;                //a variable used to determine when to fire the next cannon
 }

 var mechanics : cannonballMechanics;        //a varible used to access all other variables inside of the connected class (essentially a group)
 
 //inspector variables
 //list of default variables that can be tweaked, selected, and changed inside the inspector
 var instanceCannonball : GameObject;        //a variable holding an instance of the cannonball (which is duplicated upon firing)

 function Start () {
 }

 function FixedUpdate () {
     Shoot();                                //function put inside FixedUpdate because it handles movement over time
 }

 //function to create and shoot the cannonball
 function Shoot () {
     if (Input.GetMouseButton(0) && Time.time > mechanics.nextFire) {                                                            //checks if the user clicks the left mouse button
         instanceCannonball = GameObject.Instantiate (cannon.cannonball, cannon.spawnPos.position, cannon.spawnPos.rotation);    //creates a duplicate of the cannonball
                                                                                                                                 //at the applied position and rotation
         mechanics.nextFire = Time.time + mechanics.fireRate;
         instanceCannonball.rigidbody.AddForce (transform.forward * mechanics.force);                                            //add - or + force to the duplicated cannonball
         Debug.Log ("Fire on Target!");
         cannon.shooting = true;                                                                                                    //shows if the user is currently shooting
     } else {
         cannon.shooting = false;                                                                                                //shows if the user is not shooting
     }
 }

The error is BCE0005: Unknown identifier: 'transform'. Located inside the shoot function, it's the line: **instanceCannonball.rigidbody.AddForce (transform.forward mechanics.force);* I just don't see what's wrong with it. instanceCannonball was already declared and the variable used for adding force is declared in the class cannonballMechanics, referenced by mechanics...

Anyway, I had the same problem earlier with the error, BCE0005: Unknown identifier: 'Instantiate', located inside the shoot function, the line: instanceCannonball = GameObject.Instantiate (cannon.cannonball, cannon.spawnPos.position, cannon.spawnPos.rotation); Prior to the update I did not have to put (GameObject.) in front of Instantiate, but I checked a recent post stating the devs changed the coding. Java is more strict on defining variables. Problem is. I dont know how to edit the (transform. forward) to fix the error.

Any help or suggestions would greatly be appreciated. I'll still be attempting...

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 Caiuse · Jun 07, 2012 at 08:21 AM 0
Share

Briefly looking at your code I can't see an obvious reason for transform to be unavailable so I'll just explain what is happening when you use "transform". Using "transform" directly references the transform component on the object in which the script is attached. Try cacheing the transform in a variable then accessing it. var tr = gameObject.transform;

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by piko · Jun 08, 2012 at 05:06 AM

Sorry guys; I have figured out the issue. The code itself works but I received an error because the script bearing the code was named 'cannonBlast', which, is also, the name of a class inside the script.

So I guess Unity tried to access the script--which is a class itself when using java--against the class inside of the script. I figured it out when arkon tried pasting my code into an empty js file; I did the same thing--obviously changing the script name--and it worked.

Thanks a lot for your help on this one...

Comment
Add comment · 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
0

Answer by arkon · Jun 07, 2012 at 08:21 AM

I've just pasted your code into an empty javascript file in my game and it all works fine with no errors. I suspect it's something to do with where you have the file inside your assets folder. I put it here and it all works fine.

Game->Assets->Scripts

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Error BCE0005: Unknown identifier: 'GetAxis'. 0 Answers

Error BCE0005: Unknown identifier: 'GetAxis'. 0 Answers

Help me It keeps giving me error Unknown identifier 'Fire' 1 Answer

What is this error: x >= 0 && x < 0 1 Answer

transform.position.x brings up error 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