Search Unity

Instantiate example: Create Particle System

Discussion in 'Scripting' started by tone, Sep 14, 2005.

  1. tone

    tone

    Joined:
    Aug 26, 2005
    Posts:
    26
    I am confused by the C# scripting tutorial for this.

    There is a
    public Transform particleSystem;
    data member

    Q: Why is this not "public GameObject particleSystem"? A Particle System is not a Transform... it is a GameObject.

    Q: I see the light gray line drawn between the mention of this public datamember in the browser drawn to an inactive ParticleSystem in the scene, which I suppose is showing this script which object is the template to use in bringing a new instance to life. How would one obtain a reference to an inactive template of this kind if one wanted to create these associations programmatically rather than graphically in the editor?

    tone
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    A) Since all game objects contain a transform, (and all components pretty much mirror the GameObject interface) a transform is just as generic as a game object. Which one you have a pointer to is mainly a matter of convenience.

    A) You can naturally assign pointers programatically, but somewhere you need to do a drag connection. There are multiple reasons for this:

    * Using a naming scheme, such as sth like 'Project.Find ("Path/To/Asset"), is gonna break badly if you ever move or rename an object. With the dragging, we can track the changes... PROVIDED YOU ALWAYS DO MOVES RENAMES INSIDE UNITY.

    * We scan the connections to only include assets actually used in a game when you build it. If we allow people to do a search string, we have no way of doing this stripping.

    Stuff used for Instancing are either disabled game objects stored in scenes or prefabs stored in the assets. If you store them in the scene, they always get included and you can find them by tag. In most real-world cases, however, you store them in the project as a prefab (as you usually want to share stuff between scenes). The reason for not doing this was simplicity.

    When I create GOs for instancing, I ususally keep them in the scene while getting the basics in place. Once that is done, I move them over to a prefab (and bind the prefab to a keyboard shortcut for quick access)
     
  3. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    How do you do this?

    -Jon
     
  4. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Edit -> Load Selection
    Edit -> Save selection

    At the moment we lose the selections between app invocations, but since its all hotkey-bound (and I hardly ever quit Unity), it's not much of a deal...