Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed May 27, 2016 at 05:54 PM by heky for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by heky · May 26, 2016 at 07:56 PM · scripting problemreference

The name `FindObjectOfType' does not exist in the current context

I'm attempting to reference a public variable of one script within another by using

FindObjectOfType ScriptName (); (for some reason the little carrots make "ScriptName" dissappear but the syntax in the code is correct)

and I'm receiving this error. Can anyone tell me:

A) Why this is happening?

B) How to fix it?

C) A better way to achieve what I'm trying to do?

Comment
Add comment · Show 3
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 Hellium · May 26, 2016 at 07:38 AM 1
Share

Have you added the UnityEngine namespace ?

Please, provide the full script an use the 101010 button to format your code

avatar image Muhammad Salman · May 27, 2016 at 04:14 PM 0
Share

Can you post the code you have written?

avatar image Jessespike Muhammad Salman · May 27, 2016 at 04:43 PM 0
Share

converted your "answer" to a comment.

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by Taylor-Libonati · May 27, 2016 at 04:51 PM

It means you are calling a function that doesn't exist.

The "FindObjectOfType" method is a static function for Objects meaning you don't call "gameObject.FindObjectOfType" you instead call "GameObject.FindObjectOfType".

Where "GameObject" is the class, "gameObject" is an instance of the GameObject class and is a variable of MonoBehaviours.

In your case, since your class doesn't inherit from MonoBehaviour or Object you don't have a function called FindObjectOfType so you need to call the static function of something that does ie GameObject.

Proper use of FindObjectOfType with your own class:

 SomeClass myObject = GameObject.FindObjectOfType<SomeClass>();
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 heky · May 27, 2016 at 05:49 PM 0
Share

I've posted the code in a comment below. Thanks

avatar image
0

Answer by heky · May 27, 2016 at 05:48 PM

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System;
 
 public static class Noise {
     public enum NormalizeMode {Local, Global};
 
     public static float[,] GenerateNoiseMap(stuff) {
         MapGenerator generator = FindObjectOfType<MapGenerator>();
  

The rest of the code is irrelevant. MapGenerator is the name of another script I'm attempting to pull.

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

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Getting Int value from script to other script 2 Answers

The referenced script on this Behaviour is missing - on any new script 0 Answers

Instatiated object not being referenced in Start function? 2 Answers

Score isn't able to be counted 0 Answers

Referencing instances of scripts based on the GameObject they are attached to. 0 Answers


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