Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Shaolin-Dave · Aug 27, 2016 at 06:50 AM · c#particlesystemboxshape

Changing a Particle System shape values at runtime.

So, I have a couple particle systems in my scene with "Shape" Activated and "Box" selected. I'd like to modify the value of the "Box X" field at runtime.

Specifically, I'm trying to have the particle system match the width of the screen once it starts.

Here's what I tried, where the floats leftXpos and rightXpos are the screen edges.

 ParticleSystem ps = go.GetComponent<ParticleSystem> ().shape.box = new Vector3(rightXpos - leftXpos, 1f,1f);

and the errors I get...

  1. Assets/_Scripts/Managers/PlaneManager.cs(38,80): error CS1612: Cannot modify a value type return value of 'UnityEngine.ParticleSystem.shape'. Consider storing the value in a temporary variable

  2. Assets/_Scripts/Managers/PlaneManager.cs(38,80): error CS0200: Property or indexer 'UnityEngine.ParticleSystem.shape' cannot be assigned to (it is read only)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SohailBukhari · Apr 26, 2017 at 09:50 AM -1
Share

save shape in local var and then apply changes.

 using UnityEngine;
 
 public class ParticleTest : $$anonymous$$onoBehaviour {
     private GameObject go;
     float leftXpos = 0;// whatever you have like (Screen Edges)
     float rightXpos = 0; whatever you have like (Screen Edges)
     void Start ()
     {
        
         var ps = go.GetComponent<ParticleSystem>().shape.box;
         ps = new Vector3(rightXpos - leftXpos, 1f, 1f);
 
     }
 }

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by herDev · Apr 26, 2017 at 01:07 PM

Hi there, you can set it like this:

     ParticleSystem particleSystem;
     public ParticleSystemShapeType boxShape = ParticleSystemShapeType.Box;
     public Vector3 boxSize = new Vector3(100.0f, 1.0f, 1.0f);
 
     void Start()
     {
         particleSystem = this.gameObject.GetComponent<ParticleSystem>();
         var shape = particleSystem.shape;
         shape.shapeType = boxShape;
         shape.box = boxSize;  
     }

You'll still need to calculate the correct value for X but at least it will set it correctly now. Hope that helps!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Potter-Solutions · Apr 28, 2017 at 05:42 AM

You can create new objects for the Shape. Set it equal to the ParticleSystem.Shape and then you can modify your copy. Because the copy points to the original Shape, you are actually modifying the original values.

You can do a similar trick to modify the Box. Since this is a Vector3, just create a new Vector3 and make the original Box equal to the new Vector3.

 UnityEngine.ParticleSystem.ShapeModule editableShape = myParticleSystem.shape;
 Vector3 newBox = new Vector3 (1f, 1f, 1f);
 editableShape.box = newBox;

I don't know why this works nor do I know why Unity won't let you edit the property of the shape directly.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Problem with activating particle system 0 Answers

Can you change the Velocity Over Lifetime of a Particle System using a Script? 3 Answers

How to get newest Particle in a ParticleSystem 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges