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 vmadman · Aug 24, 2012 at 02:16 AM · c#referencetype

Error when referencing one script from another.

I am getting an error when attempting to access a method in one script from another script. I asked the question here and was told to ask the question differently.

Alright, I'm using both JS and C# because I'm transitioning to C#, but as I understand it the solution should be almost exactly the same, so, here I go:

animationManager.cs

 using UnityEngine;
 using System.Collections;
 
 public class animationManager : MonoBehaviour {
 
     // Make this game object and all its transform children
     // survive when loading a new scene.
     void Awake () {
         DontDestroyOnLoad (transform.gameObject);
     }
     
     public void sayHello() {
         Debug.Log ("hello");
     }
     
 }

I have this script attached to a gameObject named "_globalScripts", which is active in my game.

shipBehavior.js

 var kAnimMan : animationManager;
 
 function Start () {
     
     var kGloMan = GameObject.Find("_globalScripts");
     kAnimMan = kGloMan.GetComponent(animationManager);
     kAnimMan.sayHello();
     
 }

This script is attached to my player's ship. The script works otherwise and performs a number of actions.

Now, there may be some debate about the code I use inside of Start(), which is what happened the last time I wrote this question out. However, that is of little consequence because the script fails waaay before it arrives there. It actually fails on the kAnimMan declaration, with this error:

Assets/Scripts/Ship/shipBehavior.js(30,16): BCE0018: The name 'animationManager' does not denote a valid type ('not found'). Did you mean 'UnityEditor.AnimationClipCurveData'?

What I'm doing seems fairly typical. I am creating a global animationManager class and trying to run that sayHello() method on it. But I've tried several things, read several articles, and browsed for answers here without any success.

Your help is appreciated.

Edit: Fixed by this answer

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Aug 24, 2012 at 02:40 AM

This is a recurrent problem that plagues users when mixing JS and CS: the compilers are different, thus they can't see each other during compilation. To solve this, move the CS script to Standard Assets or Plugins, and move the JS script to another folder in Assets (Assets/Scripts, for instance): Unity compiles scripts in Standard Assets, Plugins or their subfolders first, and scripts in other Assets subfolders last - once compiled, a script becomes pure CIL code and can be seen by other scripts, no matter in which language they are written.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Referencing a c# component script from JS script 2 Answers

How to reference another script and call a function in C# ? 2 Answers

Refin' another script in relation to speed, and not tacking from using the Update? 1 Answer

Trying to access a variable from another script attached to same object. 1 Answer

Multiple Cars 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