Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by Maxim_Gamesnstuff_YT · Dec 28, 2021 at 05:35 PM · scripting probleminspectorsoundparticlesystem

(SOLVED) [System.Serializable] / Inspector is not working

So: I am using unity 2021.1.16f. I am currently buidling a scene with some particesystems and stumbled across the problem not beeing able to easily detect a particles death or birth, to play sound on it. Now I have tried using a technique of counting how many particles there are and if its not there anymore is makes a sound, however that worked almost, since the sounds sometimes just did not play and sometimes cut off. Anyways, I found an article (https://everfounders.com/unity-particle-system/) by a Person giving a full tutorial about how to achieve that with tricks and techniques I yet have learned. The problem is just, that the code is outdated, for example I have to write [System.Serializable] instead of only [Serializable]. And that is exactly where my real problem begins:

I am trying to reproduce this code:

 [Serializable]
 public class ParticlesInfo
 {
                  public ParticleSystem system;
                  public AudioClip sound;
                  public bool callEventsOnce;
                  public ParticlesEvent onBirth;
                  public ParticlesEvent onDeath;
                  [HideInInspector]
                  public float[] m_times;
                  [HideInInspector]
                  public ParticleSystem.Particle[] m_particles;
                  [HideInInspector]
                  public bool birthInvoked;
                  [HideInInspector]
                  public bool deathInvoked;
 }
  
 [Serializable]
 public class ParticlesEvent : UnityEvent<ParticlesInfo>
 {
 }


I changed Serializable to System.Serializable and UnityEvent<ParticlesInfo> to UnityEvent :

This is my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Events;
 
 public class PacrticleEvents : MonoBehaviour
 {
 }
 
 [System.Serializable]
 public class ParticlesInfo
 {
     public ParticleSystem system;
     public AudioClip sound;
     public bool callEventsOnce;
     public ParticlesEvent onBirth;
     public ParticlesEvent onDeath;
     //[HideInInspector]
     public float[] m_times;
     //[HideInInspector]
     public ParticleSystem.Particle[] m_particles;
     //[HideInInspector]
     public bool birthInvoked;
     //[HideInInspector]
     public bool deathInvoked;       
 }
  
 [System.Serializable]
 public class ParticlesEvent : UnityEvent <ParticlesInfo>
 {
     public ParticlesInfo[] Particles;
 }


What, so it says in the article, should show is this:

alt text

However [System.Serializable] not work. I have no ability at all, to see or change variables or other stuff in the Inspector. I don't know what I have done wrong. I did try to change my base class of ParticlesInfo to Monobehavior, but that didn't do anything at all.

So I am really Stuck and I wanna finish this until New Year, so I really hope someone can helpme with this.

Also already Thanks to everyone who will answer to this post, because that is definitly something.

2020-09-15-00h14-00.png (34.1 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Casiell · Dec 28, 2021 at 06:10 PM

Unity is serializing fields inside of ParticleEvents class. And your ParticleEvents class is empty. So you need to add fields to that class

What System.Serializable is doing, is telling Unity that if there ever is a field of that type in a class then Unity should display it in inspector. And since there are no fields, nothing is displayed

Comment
Add comment · Show 1 · 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 Maxim_Gamesnstuff_YT · Dec 28, 2021 at 07:43 PM 0
Share

Well, I now have put SerializeFields all over my Code, to see if anything would show up in the Inspector:

 [System.Serializable]
 public class ParticlesInfo
 {
     [SerializeField] public ParticleSystem system;
     public AudioClip sound;
     public bool callEventsOnce;
     [SerializeField]
     public ParticlesEvent onBirth;
     public ParticlesEvent onDeath;
     //[HideInInspector]
     public float[] m_times;
     [SerializeField]
     //[HideInInspector]
     public ParticleSystem.Particle[] m_particles;
     //[HideInInspector]
     public bool birthInvoked;
     //[HideInInspector]
     public bool deathInvoked;       
 }
  
 [System.Serializable]
 public class ParticlesEvent : UnityEvent <ParticlesInfo>
 {
     [SerializeField] private GameObject Test1;
     [SerializeField] public GameObject Test2;
     [SerializeField] 
     private GameObject Test3;
     [SerializeField] 
     public GameObject Test4;
 }

As one can see, multiple tests have been made by me, trying it behind or above the line public and private and nothing has been shown in the Inspectyor at all.

Thank u for answering tho. It could also be, that I did something wrong rn. If I did pls tell me I am bad at this yes.

avatar image
0

Answer by Maxim_Gamesnstuff_YT · Dec 28, 2021 at 10:05 PM

(Reposting this as an answer to me so eveyrbody sees it more clearly) @Casiell Well, I now have put SerializeFields all over my Code, to see if anything would show up in the Inspector:

  [System.Serializable]
  public class ParticlesInfo
  {
      [SerializeField] public ParticleSystem system;
      public AudioClip sound;
      public bool callEventsOnce;
      [SerializeField]
      public ParticlesEvent onBirth;
      public ParticlesEvent onDeath;
      //[HideInInspector]
      public float[] m_times;
      [SerializeField]
      //[HideInInspector]
      public ParticleSystem.Particle[] m_particles;
      //[HideInInspector]
      public bool birthInvoked;
      //[HideInInspector]
      public bool deathInvoked;       
  }
   
  [System.Serializable]
  public class ParticlesEvent : UnityEvent <ParticlesInfo>
  {
      [SerializeField] private GameObject Test1;
      [SerializeField] public GameObject Test2;
      [SerializeField] 
      private GameObject Test3;
      [SerializeField] 
      public GameObject Test4;
  }
 

As one can see, multiple tests have been made by me, trying it behind or above the line public and private and nothing has been shown in the Inspectyor at all.

Thank u for answering tho. It could also be, that I did something wrong rn. If I did pls tell me I am bad at this yes.

Comment
Add comment · Show 3 · 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 Casiell · Dec 28, 2021 at 11:49 PM 1
Share

You're focusing on the wrong thing. ParticlesInfo and ParticlesEvent classes are ok (at least they seem ok). What you need to change is ParticleEvents class (pretty bad na$$anonymous$$g here, those classes have very similar names, easy to make mistakes)

Your ParticleEvents class is what shows up in the inspector. And there is no fields there, so nothing to serialize.

Move this line:

 public ParticlesInfo[] Particles;

TO ParticleEvents class, it should be fine. The tutorial you are following pretty much skipped that step for whatever reason

avatar image Maxim_Gamesnstuff_YT Casiell · Dec 29, 2021 at 09:30 AM 0
Share

MAAAAAAAAAAAAAAAAAAAAAAN It was taking me A WHOLE DAY for one line wooooooow. Dude thank u sooooooooooo much like really this was mental pain this was not good. But it's ok and the code shows up in the inspectore and all works and thank u and my gposh and aaaaaa ok im done now. And yeah it is my first time for working with classes and whatever the rest is. Its new for me so I really apreciate ur help.

avatar image Maxim_Gamesnstuff_YT Casiell · Dec 29, 2021 at 09:31 AM 0
Share

@Casiell Also there i like another small bug in there, in the "finished code", but that I will move to another question. This here is solved and again thank uy very much.

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

243 People are following this question.

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

Related Questions

Arrays/Lists in the inspector of Editor Extension scripts 0 Answers

How to move an object in boundaries of a cuboid or a cube? 0 Answers

Finding Particle Information Upon Collision 2 Answers

Add a new script line to my script with text from textboxes after button in the Inspector is pressed 0 Answers

There is no GameObject attached to this GameObject 2 Answers


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