Someone could help me with a script for random spawn of an object in the Y position. I created a script but it gets giving error after I destroy it. I created ascriptbutit gets giving errorafterIdestroyit. " Code Nullo"
Could be some video, text anything. It just can’t give null error after I destroy my object.
Do you have any code we could take a look at? It also helps if you include the actual error message and then obviously the code that throws it. I’ll assume you get a NullReferenceException, which means you are trying to access something that is null. So, for example, if you create an object and destroy it, and then try to access one of its functions again, you’ll be getting a NullReferenceException since it does not exist anymore.
In order to properly help you we will need to see some code, since there are about a billion ways to implement anything and you did not offer enough information to pinpoint or fix your problem based on it.
Also, is there a particular reason for why half the words in your question link to a dictionary explaining what they mean?
Using a translator is fine i guess, but the hyperlinks are a bit annoying to read, to maybe insert the text using right click and “insert as unformatted text”. The best translator i know is probably deepl.com, so maybe you wanna check that out.
I dont know what exactly it is you want. For simple spawning an destroying, you can create a prefab object, assign it through the inspector to your script and instantiate it using Instantiate(yourPrefabObject, yourSpawnPosition, Quaternion.identity). If you want to later destroy the instantiated object, you need to keep track of it. To do that you can assign the return value of Instantiate to a class variable of type GameObject. When you want to destroy the instantiated gameobject, you can then call Destroy(yourInstantiatedGameObject) to destroy it.
If you need more than that, you need to describe your problem a bit more.
my object has 4 animations. when it arrives in the 4 animation it destroys itself.(i created an event key). now i need a script that when it arrives at a certain point in “y”, it reappears again. however all the scripts i create when destroying my object appears the error “null code” because i delete my “gameObject”. i am going crazy i am already in this problem for 2 weeks now
Why give up?
If it is about the same thing, no-ones going to tell you off.
Yoreki provided a good answer in the other post, so why don’t you try that out?
If you instantiate an object, save it in a variable, and then later destroy it, then it does not exist anymore. That’s kind of the point of destroying objects tho. So if you then check its y position, or do anything else with it, then it obviously throws a NullReferenceException since the object you are referencing is null, or in other words does not exist anymore.
If you destroy something it’s gone, including its state and everything, so it has no position you could check, or any components you could access in general, anymore. Imagine you’ve build a house. You can then, for example, use its door. What you are doing however is destroying the house and then wondering why you cant use its door anymore.
Based on what you wrote, you do not want to destroy the object, but rather make it invisible or something along those lines. To achieve that, you can simply disable and reenable the renderer, based on your conditions for doing so.
Alternatively you could spawn a new object as soon as some condition is met.
Hope this helps in clearing your misunderstandings.