I keep getting this error when I run LoadLevel and open another scene in my game. Deselecting play on awake on certain animations seemed to solve the problem for a while but then it came back. Also, setting a default animation seemed to solve it aswell but then the problem showed up later yet again. I've tried to find a way to filter out all animations in my scene to go through them but without success. Any ideas?
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEditor.AnimationSelection.GetAnimatedObjectNames () (at C:/BuildAgent/work/812c4f5049264fad/Editor/Mono/Animation/AnimationSelection.cs:424)
UnityEditor.AnimationSelection.OnGUISelection (UnityEditor.AnimationSelection animSel, Int32 width) (at C:/BuildAgent/work/812c4f5049264fad/Editor/Mono/Animation/AnimationSelection.cs:314)
UnityEditor.AnimationWindow.OnGUI () (at C:/BuildAgent/work/812c4f5049264fad/Editor/Mono/Animation/AnimationWindow.cs:2824)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
↧
Need help with MissingReferenceException AnimationSelection AnimationWindow
↧
Destroying and Loading Object Promblem?
Hi there,
I'm trying to create a presentation with a simple interaction using buttons. I created a sample scene consisting of main menu, and two different scene with three buttons. The two buttons allows you to turn on/off the lights and a back button.
And the problem comes when I'm trying to switch from one scene to another, and back again to my first/second scene. All the buttons are not working telling that the object of type has been destroyed but you are still trying to access it. Could anyone fix my problem because I'm still learning c# in unity3d.
Here's the link of my sample file:
[http://www.mediafire.com/?ec8dt0a6d5u5jbc][1]
Thanks for your help.
[1]: http://www.mediafire.com/?ec8dt0a6d5u5jbc
↧
↧
MissingReferenceException
i have i iceball hitting a paddle then that paddle is surrounded with ice,
when i tap the ice it will break and i can move the paddle again.
now, when i start the game it works the 1st time, the 2nd time i get this error :
MissingReferenceException: The object of type 'iceCube1' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
and the ice cube stays visibble, the cube can't be broken and the paddle can't be moved.
i know it has to do with "Destroy"
i tried gameObject.active=false;
but somehow the paddle won't move after breaking the icecube.
i have uploaded the snippets here :
Iceball :
[http://codeviewer.org/view/code:300a][1]
iceCube :
[http://codeviewer.org/view/code:300b][2]
[1]: http://codeviewer.org/view/code:300a
[2]: http://codeviewer.org/view/code:300b
↧
missing object woe beginner
MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
Here, I want to make explosion but it throws such exception Before destroying object.
here is my code:
var shotSound: AudioClip; // drag a shot sound here, if any
// the PickupController component of the 'PickupSpawnPoints' GameObject
private var pickupController:PickupController;
public var explosion : Transform;
function Update(){
if (Input.GetKey(KeyCode.Space)) {
Shoot();
}
}
function Shoot(){
if (shotSound) audio.PlayOneShot(shotSound); // play the shot sound
var hit: RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray ,hit ,200))
{
Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
var pickupSpawnPoints:GameObject = hit.collider.gameObject;
var clone : Transform;
if(pickupSpawnPoints.tag == "Pickup")
{
clone = Instantiate(explosion,pickupSpawnPoints.transform.position, transform.rotation);
Destroy(clone.gameObject);
}
}
}
I am currently learning unity. Please help me to solve this error . Thanx for ur help in advance,..
↧
How do I destroy a specific clone of a GameObject?
I am trying to instantiate prefabs and then be able to walk around with a first person controller and destroy the ones I deem unworthy.
public GameObject RabbitObj;
void Start()
for (int i=0;i<=RabbitInit;i++)
{
Position.x=(float)(UnityEngine.Random.value-0.5)*90f+50f;
Position.y=100.5f;
Position.z=(float)(UnityEngine.Random.value-0.5)*90f+50f;
var qq=GameObject.Instantiate(RabbitObj,Position,Quaternion.identity);
qq.name=("Rabbit"+i.ToString());
RabbitObject.Add(qq);
}
I have been using the Destroy function but it does not have the desired outcome. It deletes one object but when I try delete another object it returns the following error:
"MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it."
I think I understand why it is saying that (as it has deleted the "RabbitObj" GameObject); I just dont know how to delete just one of the cloned game objects I have instantiated.
I would really appreciate any help :)
↧
↧
Why are my (null) scripts receiving events?
I'm currently developing a piece of software where the user will perform an activity to get a score, and can go back in and perform the same activity again to improve their score.
To load the activity, we simply instantiate a prefab and disable our "player" so the prefab has control.
When the user completes the activity, we destroy the prefab with Destroy, not DestroyImmediate (though I have tried this to see if it has an effect on what I'm witnessing).
My problem is that when the user goes back into the activity there seem to be some "ghost" scripts from the previous activity load that are still receiving events. When I put a breakpoint at the top of the event-receiving functions, it tells me that "this" is null, so the script itself is null. And of course I get a MissingReferenceException, presumably because the object that held the script isn't around anymore.
I have tried to search around for an answer to why this is happening, and in my search I found someone stating that when Destroy is called, the gameObject is destroyed, but the scripts are not. Or at least they aren't destroyed immediately. From what I understand they are supposed to be cleaned up at the end of the frame where Destroy was called, presumably to give them time to finish their Updates.
Has anyone else encountered this issue? Does anyone know of a way to be sure the scripts get destroyed? It is possible that I am just doing something horribly wrong and don't realize it, but the problem seems pretty straightforward to me.
Thanks.
↧
Odd collision behaviour with If/while statement
*//That boring intro*
Hi I have a bit of a problem with a script,
I have a cannon that fires 20 bullets per second, for a second and then stops. I've tested this with different amounts of rounds per second ranging from 1, to 2, up to 120 and I'm getting some weird behaviour from an if/while statement:
var health : int;
function OnCollisionEnter(col : Collision) {
//print (col.gameObject);
var primaryGun = gameObject.Find("bullet(Clone)");
while (col.gameObject == primaryGun) {
var instance = col.gameObject.GetComponent(impact);
var damage : int = instance.primaryBulletDamage;
//print (damage);
health = health - damage;
print (health);
yield;
}
if (health <= 0) {
print ("I'm Dead");
}
}
*//The reason you hate me*
The reason I'm using an if/while type statement is because I want to create different bullet types which are essentially duplicate prefabs with some additional style changes and the parameters are different including damage, hence why the script is asking what hit it for the damage int from the collision object.
*//The actual problem*
When I use the first print, outside of the while statement, without it's comment:
print (col.gameObject);
the correct amount of collisions is printed to the console per bullet fired. However in my While loop it repeats the print function multiple times. I think this is something to do with the game refreshing each frame producing all the console prints. Without the yield; the script crashes unity/the game, also, adding WaitForSeconds(0.1); helps but it's inaccurate and sometimes still throws a good 10 prints or so for each 1 collision.
I've tried the If statement instead of while however this has the reverse effect, it only registers 1 hit per few seconds. In order for the hit to count I have to fire, wait for my original bullet(Clone) to destroy itself then it will count the next hit.
Furthermore, my final error is that,
"The object of type 'BoxCollider' has been destroyed but you are still trying to access it."
I know this is to do with the bullet destroying script that deletes the clones over time. However I don't know how to get rid of this error, the log hints at telling the script to check for null.
*//The afterword*
I hope there is someone who can help me understand better why this is happening and if there is a fix and what it might be (: also, sorry for my poor sense of humour at this time in the morning with all the cheesy *//comments...*
Thanks for reading
-Axi5.
EDIT: I just retried the first print as I mentioned earlier in this post and even though it gave 1-2 prints per 1 bullet (1 bullet sometimes counting as two or rarely, more collisions) it still didn't give nearly as many prints as while and yet it was still more than if. So I still consider this question valid despite my original test being a little off (I'll play with the collision boxes setup and see if it improves things).
↧
changing texture, MissingReferenceException
I my game you have to shoot asteroids, I have made it so that when you shoot an asteroid it changes its texture and them after yeilding destroys the object. Script attached to asteroid:
var explosion : Texture;
function OnCollisionEnter(col : Collision) {
if(col.gameObject.tag == "Laser"){ //if hit by player laser
renderer.material.mainTexture = explosion; //change texture
yield WaitForSeconds (0.07); // wait
Destroy (gameObject); // destroy object
}
}
However i get this error:
MissingReferenceException: The object of type 'BoxCollider' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
Not sure how to fix this and it would be really great if you could help me sort this out.
↧
changing texture, MissingReferenceException
I my game you have to shoot asteroids, I have made it so that when you shoot an asteroid it changes its texture and them after yeilding destroys the object. Script attached to asteroid:
var explosion : Texture;
function OnCollisionEnter(col : Collision) {
if(col.gameObject.tag == "Laser"){ //if hit by player laser
renderer.material.mainTexture = explosion; //change texture
yield WaitForSeconds (0.07); // wait
Destroy (gameObject); // destroy object
}
}
However i get this error:
MissingReferenceException: The object of type 'BoxCollider' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
Not sure how to fix this and it would be really great if you could help me sort this out.
↧
↧
Missing Reference after null Check
On start I try to run this, but get
"MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object."
if(thing!=null){//thing is referenced in the editor, so i know its there
print(thing.name.ToString());//I can access the name value of the object
//^that prints its name
print(thing.position.ToString());//error here
if(thing.childCount>0){//also error here saying it got destroyed or is missing
//it will only let me access its name
Whats going on? T.T
Edit: Can parts of objects die? I can only access the name value so far. I get the missing Reference error when i try to access this thing's position or child count.
↧
Why does my Bullet prefab go missing from my gun script when destroyed?
In my First Person Shooter game, I want my bullets to get destroyed every 5 seconds. Instead of destroying itself from the scene, it just gets rid of the prefab on the variable Bullet in my gun script.
Here is the error I get:
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:72)
UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:82)
Gun+$Shoot$16+$.MoveNext () (at Assets/Gun.js:165)
Here is the destroy script:
#pragma strict
function Start ()
{
Destroy (this.gameObject, 5);
}
Thanks and please help!!!
↧
Why does my bullet prefab get destroyed?
Hi. I'm making a first person shooter game. To shoot I have a gun script and it uses Instantiate. My var Bullet keeps going missing when ever my bullet is destroyed. If it doesn't make much sense here is the error:
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:72) UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:82) Gun+$Shoot$16+$.MoveNext () (at Assets/Gun.js:165)
Here is the bullet script and the destroy bullet script:
//destroy bullet script
function Update () {
Destroy (this.gameObject, 5);
}
//Bullet script
var BulletSpeed : float = 1500;
function Start () {
rigidbody.AddForce(transform.forward * BulletSpeed);
}
Did I do something wrong? Is there a better way to do this? Please help!!!
Thanks,
From, Anon.
↧
DontDestroyOnLoad error
So I am using DontDestroyOnLoad for my options and this is the DontDestroyOnLoad code:
using UnityEngine;
using System.Collections;
public class dontdestroy : MonoBehaviour {
// Use this for initialization
void Start () {
}
void Awake() {
DontDestroyOnLoad(this);
if (FindObjectsOfType(GetType()).Length > 2)
{
Destroy(gameObject);
}
}
}
this makes sure that the object is being deleted if it is duplicated. Now, when i load first scene and go back to menu to try and load options. I get an error:
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
This is the script I am using to display the options:
public void AccessOptions (Object myObject) {
GameObject.Find("Options").GetComponent().OptionsMenu.SetActive(true);
}
↧
↧
Unity Webplayer crashing browser
Hey all, I'll get right too it. After building to a webplayer the webplayer loads completly (fills up all the way) then crashes the entire browser.
In the Editor, the game plays fine with no errors.
My first place thought to check was the webplayer's log in:
**C:\Users\\AppData\Local\Temp\UnityWebPlayer\log**
and here are the last few lines the seem to be causing the error:
Platform assembly: C:\Users\Sam\AppData\LocalLow\Unity\WebPlayer\mono\Beta-4.63.x.x\Data\lib\System.dll (this message is harmless)
The referenced script on this Behaviour is missing!
(Filename: Line: 1788)
The referenced script on this Behaviour is missing!
(Filename: Line: 1788)
Platform assembly: C:\Users\Sam\AppData\LocalLow\Unity\WebPlayer\player\Beta-4.63.x.x\Data\lib\CrossDomainPolicyParser.dll (this message is harmless)
Anyone know how to fix/find this missing reference? I assume this will fix it, but if you know what else it could be, feel free to shout it out or let me provide any more info.
↧
How to stop Unity from destroying prefab original when destroying copied instances?
Hi everyone,
When I try to delete an instantiated (copied) Transform object from Unity, it deletes the original prefab also. When I try creating a new instance from the prefab again, I receive the following error:
MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
The copied objects are created with the Instantiate method with the original Transform in it:
Instantiate(laser, new Vector3 (posX, posY, 0), this.transform.
rotation);
The Destroy method is called in collision check method and gets the game object for destroying:
Destroy (theCollision.gameObject);
Any advice will be helpful.
↧
Referenced script behaviour is missing only when overwriting prefabs ?
I have made a simple editor for something I am working on and everything seems to work fine, but when I save a prefab over an existing one I get a console full of > The referenced script on this> Behaviour is missing!> UnityEditor.PrefabUtility:CreatePrefab(String,> GameObject)> IOHandler:SaveTilesAsPrefab(GameObject,> String) (at> Assets/Scripts/IOHandler.cs:86)> AddTiles:Update() (at> Assets/Scripts/AddTiles.cs:597)
It doesn't seem to matter if the prefab is in the scene or not, and it doesn't actually seem to break anything.. I'm not a fan of debug errors though...
The number of times that I get the error seems to equal the number of scripts on the prefab I am overwriting as opposed to the number of scripts in the new prefab e.g. save a file with 6 scripts, overwrite it with a prefab with 10 scripts I will get 12 errors.. overwrite again with a prefab of 4 scripts I will get 20 errors etc, so I assume it is a case of I should be deleting the prefab first then saving ?.. not sure how to go about that.
The code I am using to save the prefab is
// Prefab Saver ----->
public void SaveTilesAsPrefab (GameObject objectToSave, string saveName)
{
// For some reason the sphere material goes null when I save the prefab..
// could be because I manually set .material.EnableKeyword ("_EMISSION")
GameObject[] tileDataSpheres = GameObject.FindGameObjectsWithTag ("tag_TileData");
foreach (GameObject GO in tileDataSpheres)
{
GO.GetComponent().material = sphereMat;
}
// Load the save file in project window
#if UNITY_EDITOR
string path = UnityEditor.EditorUtility.SaveFilePanelInProject ("Save Prefab", saveName + ".prefab", "prefab", "Enter a name for the prefab");
if (path.Length != 0)
{
// Seems to delete the file but still get the errors even if createprefab is disbled.. very odd ;)
UnityEditor.AssetDatabase.DeleteAsset(path);
UnityEditor.PrefabUtility.CreatePrefab (path, objectToSave);
}
#endif
}//<----- Prefab Saver
This is all new to me, so sorry in advance if I am being a bit dim :)
Edit: hmmm, I tried adding UnityEditor.AssetDatabase.DeleteAsset(path); just before the CreatePrefab line and still get the errors..
↧
How to keep reference linked when replace prefab through editor scripts?
Hi,
Currently I'm woking on some editor code where I have .asset contain all the link to my prefab and these prefab can be modify/replace through another editor script.
Let's say I have a set of prefab : PrefabA, PrefabB, PrefabC
All of these prefab were referenced by ScriptableObject asset
public class AssetData : ScriptableObject
{
public List prefabList;
}
and I have another Editor script to "Replace" these prefab.
GameObject replaceGameObject = new GameObject("TEMP");
Object prefab = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject));
if(prefab == null)
{
prefab = PrefabUtility.CreateEmptyPrefab(prefabPath);
}
PrefabUtility.ReplacePrefab(replaceGameObject, prefab);
GameObject.DestroyImmediate(replaceGameObject);
The problem is after I finished replace the prefab, The reference in AssetData.asset(also happen to normal scene object serialization as well) above become a missing reference.
Did anyone ever experience this kind of situation?
Thank you,
↧
↧
Shop system using Enum throws up errors.
This is a simplified part of the script where it doesn't work,
enum Shoptype {R_Rock,R_Iron,R_Silver,R_Gold,R_Gems,R_Uranium,R_Voidium,R_Zarkotium,R_Omnium,ShipFuel,ShipHull,ShipMissiles};
var whichResource : Shoptype;
var ThePlayer : PlayerScript;
function OnMouseDown(){
if(sellbutton == true){
if(sellall == false){
if(ThePlayer.whichResource >= amount){
ThePlayer.whichResource -= amount;
ThePlayer.Money += (price*amount);
guiTexture.color = Color(0.25,0.25,1,1);
}else if(ThePlayer.whichResource < amount){
guiTexture.color = Color(1,0.25,0.25,1);
}
}if(sellall == true){
if(ThePlayer.whichResource >= 1){
theamount = ThePlayer.whichResource;
ThePlayer.Money += (price*theamount);
ThePlayer.whichResource -= theamount;
guiTexture.color = Color(0.25,0.25,1,1);
}else if(ThePlayer.whichResource == 0){
guiTexture.color = Color(1,0.25,0.25,1);
}
}
}else if(sellbutton == false){
if(ThePlayer.Money >= price){
ThePlayer.whichResource += theamount;
ThePlayer.Money -= price;
guiTexture.color = Color(0.25,0.25,1,1);
}else if(ThePlayer.Money < price){
guiTexture.color = Color(1,0.25,0.25,1);
}
}
}
it puts this error at the line,
if(ThePlayer.whichResource >= amount){
"NullReferenceException: Object reference not set to an instance of an object"
not sure what's going on here, I don't work with enums alot.
↧
Reference scripts just keep missing...
I recently upgraded to Unity 5. I began working on a complete new project and was fine for the first two days, but now I keep getting strange errors.
Working with the new GUI interface(Canvas, image) every time I run the game I get an error, multiple errors: "The referenced script on this behavior is missing." When I check it, the "Image" script has disappeared. This happens every time.
Prior to this, one of my GameObjects has done the same thing, only it references an error in the script(Null Reference I believe) that when debugged and etc. gives no errors...
And lastly to add to this missing scripts, I also get this error:
"GameObject (named 'Inventory') references runtime script in scene file. Fixing!"
To fix these temporally I close the entire project and reopen it, but does not always work... I'm at a loss trying to figure out if its an Unity Bug or one of my scripts.
![alt text][1]
[1]: http://i.imgur.com/r9vnU50.jpg
↧
Canvas Problem
Hello,
I got a problem with my canvases , When i just turn off unity for some minutes and then again turned it on and i was shocked that my canvases are gone and i got some error , i created those Ui for my game in 24 hours and it was liked washed up or something , can anybody please help me how do i recover them, i got some errors and the scripts in the ui are missing . all ui scripts are missing .
Here are the pics of errors(both errors those are out of line are also covered in the pictures so you can fully check them) and script missing .
![alt text][1]
![alt text][2]
[1]: /storage/temp/48719-upload-1.jpg
[2]: /storage/temp/48720-upload-2.jpg
↧