For some reason particles are not being instantiated on collisions.
There is a record (print) of the collision being made, but I can’t make particles to appear.
Doesn’t work for enemies and for the player death.
For some reason particles are not being instantiated on collisions.
There is a record (print) of the collision being made, but I can’t make particles to appear.
Doesn’t work for enemies and for the player death.
Hi Yaroslav,
There are a few reasons why this might appear to be the case.
NullReferenceException
error most likely)The above are just some reasons why it may seem they are not appearing.
I would be happy to take a look at your project if you would like to share your project files?
The forum will allow uploads of up to 10MB, if your project files (zipped) are larger than that you would need to use a service such as Google Drive or Dropbox, and then share the URL.
Rob, the project got pretty big, with all asset packs and all.
I am zipping it, but still it will have 200-400Mb.
Maybe I can provide you with access to collab for that? I use Collab together with Git.
If it’s possible, then I just need an email to which I need to provide the access.
If no, I can send the link in a bit.
Hi,
That’s ok, just the URL to download a copy of it will work for me at this end, as and when you’re ready
Here is the link: https://acgedu30684-my.sharepoint.com/:u:/g/personal/y_kozak_acg_edu/EQuRfy6nB3BIkIYuJdrK8tUB54AcwivN7_GxOedl4lX4JA?e=asxdho
Please, let me know if you can access it?
Thanks, downloading now. Give me about 15 minutes to get it, open it, compile it and then I’ll reply again
Updated Thu Dec 06 2018 21:40
The downloaded zip contains a text file named _"AllErrors.txt" which contains this messages;
“Some files weren’t downloaded. The limit of file downloads has been reached. The total number of file downloads cannot be greater than 200”
I’m going to hazard a guess that I do not have a complete copy of your project. In fact, after just checking, all I do have is the bulk of the .git directory which doesn’t really help at all.
Could you try Google Drive / Dropbox etc, clear the SharePoint site isn’t going to play nicely.
Here is the link to Google Drive:
https://drive.google.com/open?id=1vDSsj5tQDvE50vqa5xChRWjsb-Q7BVdQ
Sorry, there was some kind of restriction on Sharepoint before.
Hi Yaroslav,
That’s fine, these things happen
I will download now and take a look as soon as I can
Hi,
I’ve taken a look. I can see from the Hierarchy that your explosion prefabs are being instantiated;
Looking at the code within Enemy.cs I see this;
void OnParticleCollision(GameObject other)
{
GameObject Effects = Instantiate(deathFX, transform.position, Quaternion.identity);
Effects.transform.parent = parent;
Destroy(gameObject);
}
You create an instance of the prefab, as a GameObject, and parent it to the Runtime GameObject underneath your terrain, you then destroy the Enemy GameObject.
Your ParticleSystem is not set to play at any point, and as it is not set to prewarm it isn’t going to just do this on its own.
Update your OnParticleCollision
method as follows;
void OnParticleCollision(GameObject other)
{
GameObject Effects = Instantiate(deathFX, transform.position, Quaternion.identity);
Effects.transform.parent = parent;
Effects.GetComponent<ParticleSystem>().Play();
Destroy(gameObject);
}
Now, after setting the parent, your code gets a reference to the ParticleSystem on the GameObject that you have instantiated, it then calls the Play
method of the ParticleSystem component. Your effects now appear when you run the game.
In your Enemy.cs script you are adding a BoxCollider component to the Enemy GameObject, however you already have this component on the enemy GameObject in the scene. I would suggest going one way or the other, e.g. either have the BoxCollider as a component added to the Enemy prefab, or, add it at runtime, not both.
I also spotted that you have the Enemy.cs script as a component of the Enemies GameObject in the Hierarchy which is unnecessary, as is the BoxCollider component which you have currently disabled;
I am noticing that as soon as I play the game I am hearing the explosion sound effects. As you have Play On Awake set for these that would indicate that the GameObject that the sound effect is a component of has been instantiated, and that object is an instance of your Explode prefab. Looking further I see that you have this as a child GameObject of the Player, and it’s active. From memory, I think this was supposed to be disabled and then enabled in code when the explosion took place - you’d have to check though.
There are a number of warnings in your console, not solely of your doing, but these will become distracting for you when you are trying to output/see information that you want;
Initialise your xThrow and yThrow fields within PlayerController.cs to remove these;
float xThrow = 0f;
float yThrow = 0f;
Removes lines 35, 36, 95 and 96 from CrossPlatformInitialize.cs to clear these;
Change line 24 of TimedObjectDestructor.cs from;
DestroyObject(gameObject);
to;
Destroy(gameObject);
Change line 57 of ActivateTrigger.cs from;
DestroyObject(targetGameObject);
to;
Destroy(targetGameObject);
Change line 11 of SimpleActivatorMenu.cs from;
public GUIText camSwitchButton;
to;
public Text camSwitchButton;
and add the following using directive at the top of the script;
using UnityEngine.UI;
Change line 6 of ForcedReset.cs from;
[RequireComponent(typeof (GUITexture))]
to;
[RequireComponent(typeof (Image))]
and add the following using directive at the top of the script;
using UnityEngine.UI;
Note: If you re-import the Standard Assets at any point again, you may over-write these changes and end up with the same issue
A better approach may be to spend some time determining which of the Standard Assets you actually want/need, and then remove the reset. Whilst they will not be included in your build they do tend to clutter up your project and cause issues like the above some times. Be aware, some scripts have dependencies on others. It is often easier, in the case of the CrossPlatformInputManager to just add the script you think you need, and then look at the error messages Unity creates when it advises that it also needs this script and that script, you can then re-import those to support it.
You may also want to check which Standard Assets you imported, the Asset Store has two versions available, the current version and an older version - some of the obsolete items corrected above were changed around version 4.6 of Unity which is fairly old now.
You can tell them apart by the image they use in the Asset Store;
(Unity 4.6 or higher)
(Unity 5.0 or higher)
The latter won’t contain the same legacy GUI issues we’ve seen above.
Hope all of the above is of use
Rob, this is awesome. I applied all changes you suggested. All works and performs as expected.
Thank you a lot.
The errors have also been resolved.
Sorry for the mess with box colliders - I was very irritated and tried all around to see if maybe there was an issue with colliders.
I have removed those as well (I believe it’s better to keep it in scripts and create on the go)
Regarding effects - my main issue, I was not sure what was causing it. And I also tried to use your names for vars and tried with the script you have on gh. Still it did not work so i presumed, the problem might be in the inspector.
Right now, I see, that the problem was the actual Activation of the Effects:
.GetComponent<ParticleSystem>().Play();
I have been following lectures when it comes to scripts and that’s why it seemed weird.
Also, the repo does not contain tis line: https://github.com/CompleteUnityDeveloper2/4_Argon_Assault/blob/master/Assets/Scripts/Enemy.cs
Maybe, it’s because the structure there is more polished and some things were resolved in some other way that will be revealed in next lectures.
For now, just so you know how this issued happaned to me. In case it reoccures.
Thank you a lot for the help, Ill continue with the project now ^)
Hi,
You’re very welcome and there’s no need to apologise regarding the BoxColliders, it was just an observation, but if I didn’t let you know then later on you may wonder why things happen twice perhaps when a collision is made
With regards to that line of code not being in the repo, it may be that you haven’t set your explosion prefab up in the same way as the course. So, my fix above, is based purely on what you have in your project, as opposed to being directly in line with the course content. If you want to have things more in line, it might be worth going back of the section that introduces the explosions and see if you can spot any differences between the course material and what you have.
Looking at a copy I have hear of the completed project I note that the Enemy Death FX prefab has this setting for the Particle System;
I don’t have your project to hand now, but if you check your Explode prefab, look at the Particle System and see whether this is ticked or not, if it isn’t that’s the main difference. You can tick this box and then remove the line of code I gave you above earlier.
Hope this helps and enjoy the rest of the course
I see.
Ok, this is great then.
Too many settings with particles and I indeed missed this one^) All is clear now.
Thank you for the fast responce.
Have a good day ^)
No problem at all
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.