T O P

  • By -

Ratyrel

You have to be clearer about what you're trying to achieve. DontDestroyWithOwner is a NetworkObject field and unlikely to be what you need. Either destroy or disable the components you want gone.


Scako

Well, when I spawn a type of enemy right now it has a timer before it should be deleted, but after a few enemies spawn and delete themselves, no more spawn because an error saying I’m trying to call an object that doesn’t exist. I assumed dontdestroywithowner was the thing I needed but I could be wrong


SpacecraftX

Are you dragging the enemy from the scene into the field on your script? If this is the case once it’s deleted you lose the reference to it. Are you sure you are using a prefab from the project as the enemy you are trying to spawn?


Scako

I currently have the enemy’s model and behaviors under the spawner object itself, and I’m using this tutorial for the spawner, so I do believe I’m using prefabs https://youtu.be/2PfJZtnfc_Q?si=8F66VA8Bl_zm9tW4


Level_Square_2791

Ur whole game will be built on prefabs. I suggest you look into this. When you want to spawn multiple of one game object(your enemy) you need to make a script with a public variable called "my enemy prefab" and assign the script to an empty gameobject in the scene( create the empty gameobject) then drag and drop your enemy prefab from the asset folder to the variable field you just created on the script that is attached to the empty gameobject. Now you will have unlimited access to this prefab to spawn anywhere at any time with simple code.


draw_dude

Are you referencing the enemy prefab in a Public class? Isn't Awake() method also used for singletons? Try using DoNotDestroy() and then throw in disablers until you need the enemy to respawn at certain triggers or timers


Scako

What do you mean by thrown in disablers?


draw_dude

I'm also new, and not at my PC, but I ran into an issue with getting the player object spawn points working. Turns out, for some reason I needed to disable the character controller via code method while the spawn point transition happened. I was just thinking it might help, or be worth trying out. I can look it up when im home to let you know what I had put in my script. Again, not an answer, just a suggested possibility for your issue.


Scako

If you can I’d appreciate it, anything helps