Space Shooter Tutorial issue (bolts are static on instantiate)

Hi,

Wonder if you could help.

I’m following along to the Space Shooter tutorial. Great by the way.

I’ve got to the point where I have added Shot, Shot Spawn, Fire Rate to the player object.

When I click play to test it, the first bolt that is instantiated fires fine and disappears off the screen but all subsequent bolt (clones) just stay in the original transform position in front of the ship. They don’t move forward. So as I move the player around the screen, and press left click, it just leaves lots of static bolts on the screen that don’t move forward.

I’ve checked the Mover script and PlayerController script and they are typed exactly as the tutorial typed it, so I’m a bit baffled.


Any help would be much appreciated.

Kind Regards

Andrew Kennedy

Can you please post the code attached to the bolt prefab?

I assume that the bolt has a mover script attached that sets its velocity?

And a screen shot of the prefab GameObject’s inspector in the editor?

You can post your code as text in the post, just remember to use code tags:
Link:Using code tags properly

using UnityEngine;
using System.Collections;

public class Mover : MonoBehaviour 
{

    public float speed;
    
    void Start()
    {
        rigidbody.velocity = transform.forward * speed;
    }
}

1608553--97597--$boltcode.PNG

Do you have any errors in your console?

This came up:

1608652--97626--$error.PNG

That seems to indicate that the “Is Kinematic” button is being set on the Prefab.

I don’t see “Is Kinematic” set on the image of the prefab that you linked above.

Next step: Check the instantiated object.

  • Enter play mode.
  • Fire your weapons until you have static, non-moving bolts.
  • Check the instantiated GameObject in the inspector.
  • Is the “Is Kinematic” property set on the Rigidbody?

Take a screen grab of the Instantiate Prefab and let’s take a look…

So,

I noticed that when play-testing the speed of the bolt clones gets reset to 0.
This was because the prefab was set to 0 and I then changed it to 20 when it was in the hierarchy.

I deleted the prefab, made a new one making sure that the speed was set to 20, so all clones get set to a speed of 20 thereafter.

Thanks for your help. Sorry, my mistake.

Ah - you can make a change to the prefab in the hierarchy, but then you must click the “apply” button, to apply the changes from the instance to the prefab asset!

If you change an instance, you must hit apply for it to propagate to the asset and other instances.

Ok, thanks.

I should have been clear why.

This allows the developer to override the values on any particular instance without affecting the prefab asset.

If you want to make torch and the prefab uses a light with a yellow colour, it is possible to override the colour of the light on any particular instance and change that particular torch’s colour. This is an override on one instance.

If you want to have ALL the torches changed to this colour, you can then “apply” the changes using the apply button. Then the asset is updated and all of the instances (that are NOT overridden) will have that new updated colour. If you have overridden a property (say colour, in this case) and you make a change to the prefab asset or apply a change from the instance, these changes won’t affect the overridden instance.

This is done on a property by property basis… so If you change on your torch, for example, the colour and intensity of the light on the torch (either on the prefab asset or by applying a change from an instance) and you have an instance of a torch where you have already overridden the colour, the colour won’t change but the intensity will, as the intensity is NOT overridden and is still referencing the prefab.

http://unity3d.com/learn/tutorials/modules/beginner/editor/prefabs-concept-usage

(Oddly enough, that video doesn’t mention overriding a prefab’s property)

Ahh, ok, I get it. Thanks very much for your help.

You have been very informative, and I have been really enjoying these tutorials. Unity is a great game engine and is something I think I will continue to try and learn and perfect.

I am currently learning C++ with a teaching body which is much harder but useful in the long run. But I think when I have completed my C++ studies I will make the switch to developing in Unity, and just use the skills I’ve gained in C++ to my advantage in Unity.

Thanks again :slight_smile:

You can include C++ code in Unity projects by creating plugins.

I have not done this, but here are two docs pages:

I seem to have come across another problem. The bolts are not displaying on the screen. They are firing and destroying the asteroids but they are invisible.

Not sure why as the inspector shows that the shader is on there and mesh renderer with fx_bolt_orange selected.

1609632--97734--$boltinspector.PNG

I don’t see anything overtly wrong with this screen capture.

Is this from run-time?

One test would be to drag an instance of the prefab into the scene and see if it works at edit-time and that the prefab is correct…

Your layer is default, so it shouldn’t be culled by layer (you can ask cameras to ignore certain layers)…

I assume that your game is all playing on the x-z plane where y is 0, and everything is within the camera’s frustum…

If you look at your material by selecting the material asset directly or clicking on the Material Element 0 (fx_bolt_orange), does your material look correct?

Are you getting the expected texture? Is the texture attached? Is the materials “alpha channel” set to 0, so it’s transparent?

Rotation was set wrong for the VFX quad for the bolt.

Always something simple :slight_smile:

It shows rotation x as 0 in the screenshot above, but I changed it to 90 and worked even though the bolt was facing the wrong way in Scene mode.

Strange

Try instantiating a few quads. This may be covered in the tutorial as well… But, iirc, Quads are oriented to the X-Y plane facing the default camera position, so in our top down view, they would be invisible.

Mustang, Im facing almost the same problem as you were. The bolts sometimes displays and sometimes dont. They are firing and destroying the asteroids but they are invisible. But its intermittent and it only happens when I build for Android.

Any tips?

Please, can you repost your question on the official thread in teaching? It is a sticky on the first page. I’ll answer there.