Search Unity

[Solved] Can't change ParticleSystem startSize

Discussion in 'Scripting' started by Josiah_Ironclad, Apr 26, 2020.

  1. Josiah_Ironclad

    Josiah_Ironclad

    Joined:
    Sep 24, 2019
    Posts:
    156
    I've been across 3-5 different Unity Docs and Scripting API pages, and I'm pretty sure I'm doing this correctly, but I'm getting an error.

    'ParticleSystem' does not contain a definition for 'mainModule' and no accessible extension method 'mainModule' accepting a first argument of type 'ParticleSystem' could be found

    Code (CSharp):
    1. public GameObject explosionPrefab;
    2. public ParticleSystem.MainModule mainModule;
    3.  
    4. void Update() {
    5.  
    6.     GameObject explosionParticles = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
    7.     mainModule = explosionParticles.GetComponent<ParticleSystem>().main;
    8.     explosionParticles.GetComponent<ParticleSystem>().mainModule.startSize = fragmentSize;
    9. }
    The error is pointing to the last line (8).
     
    Last edited: Apr 26, 2020
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,749
    In line 7 you are already getting the mainModule to a temporary variable (a necessary step).

    In line 8 use that variable to access .startSize.
     
    Josiah_Ironclad likes this.
  3. Josiah_Ironclad

    Josiah_Ironclad

    Joined:
    Sep 24, 2019
    Posts:
    156
    Thank you! It works.
     
    Kurt-Dekker likes this.