x


#pragma strict GetComponent from Javascript to C# fails

Hey guys, I am having a problem getting a Javascript file to get a C# script that is on the game object. This is using #pragma strict.

I already moved the C# script into the Standard Assets folder and I still get this error:

Assets/Standard Assets/MyScripts/Enemies/SentryAI.js(37,41): BCE0018: The name 'Seeker' does not denote a valid type ('not found'). 

Here is the line of coding causing the problem:

(this.GetComponent("Seeker") as Seeker).StartPath(this.transform.position, waypoints[currentWay].transform.position);

I have tried all kinda of different GetComponent iterations, and I still come up with the exact same error.

Thanks in advance, Jason

more ▼

asked Jan 30 '11 at 10:07 PM

D2king10 gravatar image

D2king10
1 1 1 1

I think it's the "as Seeker" part that's the problem, not GetComponent. Where is your Seeker class defined? (Have you tried this.GetComponent()? I don't expect it to work either, if it can't find the Seeker class, but this usage is cleaner for C#.)

Jan 30 '11 at 10:44 PM yoyo

Take a look in your asset folder (not in unity, use your Explorer[win] or Finder[mac]) and check the name of your C# file. It should be called "Seeker.cs". And check your C# file and make sure the class is also named "Seeker" (case sensitive!!)

Jan 30 '11 at 10:49 PM Bunny83

@yoyo: the script above is a JS script. If using the generic version in JS you have to use GetComponent.()

Jan 30 '11 at 10:52 PM Bunny83

I checked the location just in case, and it is correctly placed in the Standard Assets folder and the files are named correctly. I have tried the GetComponent() and it still throws the same error.

If it means anything, this is from the A* pathfinding package I installed on unity, which then I manually moved the folder into the Standard Assets folder, but it is still flagging the error.

Jan 30 '11 at 11:02 PM D2king10
(comments are locked)
10|3000 characters needed characters left

2 answers: sort newest

Mixing JS and c# is not recommended unless you keep your code interdependencies very clean. C# gets compiled first and so don't have awareness of JS scripts.

Switching your code to C# is recommended. You also get extra candy like auto complete.,Mixing JS and c# is usually a nightmare. c# gets compiled first and so don't have awareness of JS scripts.

So ask yourself if you want to make the effort and switch over to CS or keep banging your head.,Is switching to c# an option ? Mixing JS and c# is usually a nightmare. c# gets compiled first and so don't have awareness of JS scripts.

more ▼

answered May 23 '11 at 08:33 PM

mcdroid gravatar image

mcdroid
103 3 3 6

I think mcdroid is a robot! with a bad algorithm that's repeating itself.

Jan 09 '12 at 02:46 AM Silx
(comments are locked)
10|3000 characters needed characters left

I was only able to get it working if I did one of two things:

1) Move the .js outside of standard assets and keep the C# script in the standard assets folder. (this caused more errors with objects wanting to reference the .js so this was no good.

2)I had to create a function in the seeker.cs file to do what I was doing, and use

gameObject.SendMessage("PathWaypoints", waypoints[currentWay].transform.position);

Hope that helps someone.

more ▼

answered Jan 31 '11 at 08:57 AM

D2king10 gravatar image

D2king10
1 1 1 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x405
x29

asked: Jan 30 '11 at 10:07 PM

Seen: 2587 times

Last Updated: Jan 09 '12 at 02:46 AM