• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Script from JS to C# 1 Answer

Distribute terrain in zones 3 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

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges