How to create particle on object?

Hey everyone,

I’m asking for help in the Argon Assault lessons, specifically getting the explosion particles to play when the enemy is hit with the particles.

I know the code works because I hear the audio source play when the enemy is destroyed, but the particle effect is never played. I think the issue is that I can’t create the particle on the position of the enemy, but viewing the game running in 2by3 mode doesn’t show the effect being created at all, even though again I hear the audio so I know the code itself is working.

Cheers everyone

EDIT: I just wanted to say that I can confirm that it’s the location that is the issue. After increasing the size of the particle, it’s being created way below the object terrain itself, so my problem is the inability to create the explosion at the same location of the destroyed ship, even when using ‘Instantiate(deathFX, transform.position, Quaternion.identity);’, so is there a way to set the Origin of the object like there is in Blender?

Check your deathFX prefab is at 0,0,0 because its instantiating at the transform.position of the object its attached to which is local 0,0,0 if you have a transform set to anything but 0 it will be offset from the position.

I can confirm its at 0,0,0, but even at crazy numbers such as 0,60,0 its position never changes it seems.


Hi Arthur,

First of all, check if your deathFX got spawned in your scene. You could add a little test script to the prefab, which logs a message into your Console. It might well be that the instantiated game object gets destroyed immediately.

Also check your Hierarchy while playing your game. Does a new game object appear? Maybe for a brief moment? Or longer? If it remains in the Hierarchy, pause your game and double click on the game object. Maybe your deathFX got spawned at the wrong position.

As Marc indicated, the different spaces in Unity can be a bit tricky.

I already know that it spawns, it just does way below the destroyed enemy instead of on it. Is there a code I can write to just have it create at the object’s location?

Below? Is it falling? If not, does it appear at the same position or with the same offset relative to the destroyed enemy?

The best would be to log the transform.position of your enemy and your instantiated deathFX into your console.

It’s not falling, it just spawns below the object by a considerable amount.

Here’s the print of many particles to many destroyed ships:

particle location = (11.0, -1.0, 0.9)

particle location = (6.2, -1.0, -0.9)

particle location = (11.4, -1.0, 2.4)

You can see that -1 is the common variable here, and I checked the transform of the particle and its 0,0,0, so I still can’t figure out why that’s the case. Although I think -1 maybe the bottom of the the level, so it’s being created on the ground, maybe?


And where is the enemy? I’m wondering if your enemy has got a child game object with an offset. Could you share screenshots of your Hierarchy? To which game object is the script attached which instantiates the deathFX? transform.position refers to that game object and its Transform respectively.

The enemy and particle have the exact same transforms.

Script is attached to a created empty object that I then added the ship model to. I can confirm that when you attach the script to either the ship model or the object with the ship model in it, it yields the exact same results.

Could you upload your project folder to GitHub without the Library and Temp folders? If you do not know how to do that, please watch Ben’s videos on version controlling.

I’d like to look into your project.

I uploaded it, do I just paste a link here? Should the link have my name and the name of the project in the address right after

That’s correct. Here is an example for Ben’s and Rick’s repo. Check your link in an icognito tab in your browser because it might be that your repo is private. If it is, make it public, please.

Sorry for the late reply, I forgot the password to github so I wasn’t allowed in for a bit, haha!

Here’s the link:

Couple of things to point out tho:

  1. I’ve been creating my own low poly assets, so the size of my project level is considerably smaller than the actual assets (my terrain was around 2,000 faces more or less, in comparison to the average terrain from the tutorials that were well over 100k), I imagine this might be a reason for the issue, but I’m not sure.

  2. The actual controls for moving the ship are different from the course (I’m not using cross platform libraries), and I’m using a path engine that’s not the same as the circuit one in the standard assets, but I’m confident that those aren’t the reason for the issue, as I don’t see how they relate to the issue at hand.

Finally, I’m also facing the issue of creation in the wrong location with the bullet particles as well. They’re being fired when I press the fire button, but don’t come out of the ship, even though when they fired at launch it was always on the ship’s location at all times.

Hope this helps you figuring out what the issue is.

Cheers Nina, thank you for your time.

Hi Artur,

I’m sorry for the late reply. I must have missed your thread but thanks to the bump bot I got another notification. :confused:

Did you already fix the problem?

I’ve just forked your project on GitHub and updated your project to Unity 2019.2.13f1 because I don’t have your version of Unity installed. There is no relevant difference between the versions anyways regarding this project, so updating should not cause any additional problems.

I created a new branch, so you hopefully will not get any conflicts if you already continued working on your project.

I’ve tested Level 1 and noticed that the ship is not shooting. The ActiveGuns method gets called, the bullet position printed but Bullets does not get enabled in the Inspector even though it is referenced correctly.

The reason for this is the GetButtonDown method which returns true only in the frame when the button was pressed down but not in the next frame.

A quick fix:

    bool gunsActive = false;

    void ProcessFiring() 
        if (Input.GetButton("Fire"))
            if (!gunsActive) { ActivateGuns(); }
            gunsActive = true;
        else if (gunsActive) 
            gunsActive = false;

The particle system is not emitting the particles, not even in the editor when the game is not running.

I created a Shooting_Test scene. The enemy is exploding correctly when hit by a bullet. If you check the scene, do not apply the changes because it might be that I disabled a few things. The player is falling down due to the PlayerController script, so you will have to hurry up a bit.

I fixed a NullReferenceException in that scene which prevented the OnParticleCollision method from being executed correctly. If you wonder what the question mark is supposed to mean:


// means
if (scoreBoard != null) { scoreBoard.ScoreHit(scorePerHit); }

It’s a feature that was introduced in C# 6.

The Explosion game object does get instantiated at the pivot point of the enemy but the mesh has got an offset.


The player shooting at the enemy:


The explosion:

Reset the origin / pivot point of your mesh in Blender (or whatever modelling software you use).

I sent you a pull request via GitHub so you can pull my commits if you want.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms