Search Unity

setting particle system collision layer through C#

Discussion in 'Editor & General Support' started by Tekksin, Sep 23, 2018.

  1. Tekksin

    Tekksin

    Joined:
    Oct 20, 2013
    Posts:
    32
    I'm using this as a reference:

    https://docs.unity3d.com/ScriptReference/ParticleSystem.CollisionModule-collidesWith.html

    but
    var collision = ps.collision;
    collision.collidesWith = (1<<layerNum)
    doesn't work.

    unity tells me:
    NullReferenceException: Object reference not set to an instance of an object
    PowerCollision.SetTarget (Int32 i)

    I'm literally following the documentation, and just not doing a toggle. What in the world is going on?
    And also, can you set multiple layers instead of just one? @_@
    Halp.
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Make sure you've actually got ps variable != null.
    Also, make sure the collision module is enabled.