• 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 kag359six · Aug 29, 2012 at 11:08 PM · transformobjectinstance

object not set to instance..........again.

So i have had this issue before, and it has been dealt with in a different scenario, however i can't come to a solution for this one. when i call a function in another script it tells me that it needs to be set to an instance of an object, and im assuming its refering the the "this.transform" part. What's a work around for this?

  else if(!terrain.chunksToRender.Contains(this.transform)) { 
             
             terrain terrainScript = player.GetComponent<terrain>(); 
             terrainScript.renderChunk(this.transform); //here lies the issue
             terrain.chunksToRender.Add(this.transform);
             
         }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Cripple · Sep 04, 2012 at 09:50 PM

Hi,

It must be terrainscript which has a null reference. Are you sure that you have attached the script terrain to your GameObject player ?

If you want to debug, just try something like this :

 terrain terrainScript = player.GetComponent<terrain>(); 
 if( terrainScript == null)
 {
          Debug.Log("terrain script not found");
 }
 else 
 { 
          terrainScript.renderChunk(this.transform);
          terrain.chunksToRender.Add(this.transform);
 }

You should also give your script/class name a name starting with a upper case, it is a C# convention. Here you should have "Terrain" instead of terrain.

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 kag359six · Sep 04, 2012 at 10:49 PM 0
Share

SWEET. It turns out that player didnt have that script, it was some other object and i totally forgot that i assigned it to a different object lol thanks.

avatar image
0

Answer by Screenhog · Aug 29, 2012 at 11:18 PM

Can't you just do "transform" instead of "this.transform"? I don't know if the word "this" is actually used anywhere in Unity.

Comment
Add comment · Show 3 · 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 kag359six · Sep 04, 2012 at 09:26 PM 0
Share

That still gives me the same "object reference not set to instance" error.

avatar image AlucardJay · Sep 04, 2012 at 09:31 PM 0
Share

this. is accepted by Unity, just as the keyword new (new Vector3) is accepted in uJS. They are not required, but they work =]

Sorry, I cannot help with your problem in C# though, it is merciless if you don't declare things as it likes :(

unless it's something simple like the method renderChunk is not set as public void?

avatar image kag359six · Sep 04, 2012 at 10:49 PM 0
Share

Cripple's answer was correct

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

9 People are following this question.

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

Related Questions

Adding data to a set of transforms 1 Answer

MissingReferenceException Help 1 Answer

How to manage an object using joints? 0 Answers

problem with wheelcollider 0 Answers

rotation of the object to a given angle 1 Answer

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