Type AudioClip?

When Rick had written “[SerializeField] “Type” AudioClip” he got the field for choice of the AudioClip in the Script component.
But how does it work?
Why do I get the error when I am writing for example "[SerializeField] Mass(Rigidbody component) " ? ( I had tried to experiment)
Maybe Unity has a library with all possible “Type”, but “Type” Mass hasn’t, but I’m not sure.
Could somebody help me to find the answer?
Or please describe why one type works but with another no.

A ‘Type’ is the name of a class. AudioClip is a type. So, Unity can go through all the assets and find the ones that are of that type. Mass(Rigidbody component) is not a type. It’s not even valid code.

What are you trying to achieve? It would be easier to help if I know what you are hoping to do

In this lesson, I saw a new feature, And I’m trying to figure it out.
How can I use this feature in the future?
For example, I know about classes and methods, know how I can call them, and know where I can find the information about all classes and methods for understanding how to use them in a code.
But what about this feature where I can find information about “Types” for Unity to use them as Rick uses the “Types” AudioClip?

I’m really sorry. I don’t understand. I watched the video referenced by this post and Rick never type [SerializeField] "Types" AudioClip

Do you perhaps mean the auto-complete/IntelliSense? That is built into the IDE. The first lecture shows how to set up an IDE to have these for Unity

I mean this moment.

The course “Project boost”
Lesson 48 - Multiple Audio Clips
Timeline - 5 min.

Are you talking about this tooltip?


This is IntelliSense. It’s built into the IDE and you can set it up to work with Unity, it just depends on which IDE you are using

At the beginning of the course there’s a video showing you how to set up VSCode for this

To get this done on your own classes/properties/methods you’ll use xml documentation feature. You use 3 /// (and a decent IDE will autocomplete some stuff for you) and type some documentation that will show up in the IntelliSense

See here

Oh cool thanks useful thing.

But it doesn’t answer my question = ( .
I try to explain what I want in another way.

Rick wrote - [SerializeField] AudioClip mainEngine;
In the video, he said -

It’s going to be a type AudioClip.
That’s the type of variable we’re creating and we will call this what is it, MainEngine.

He calls the AudioClip is “Type”.
After he saved the code, in the script component in the Unity interface appeared a field for using Audio files.

But the AudioClip it’s the field or parameter in the AudioSource component.
That confused me I thot "Oh what if write the same but with any other parameter for example “Mass” " and I did it, but got an error.

And I want to figure out, what is “Type” and what kind of “Types” I can use in a code to add any other parameters taken from any components or add parameters like an AudioClip.

It’s like I said in the first post; A ‘type’ is the name of a class. AudioClip is a ‘type’, Renderer is a ‘type’, Transform is a ‘type’, any script you create is a ‘type’, MonoBehaviour is a ‘type’

AudioClip is a field of AudioSource but this has nothing to do with what Rick wrote. AudioSource has a AudioClip field, and Rick added a AudioClip field to the CollisionHandler component. That’s all.

Сool thanks this explains a lot.

Type is short for Data Type of a variable, such as float, int, bool, or any other variable data type.

A class like AudioSource is in a way a variable data type on its own, though a more complex one, so before you declare it you have to declare its data type the same way you would for any other variable like an integer or a float.

If you declare the wrong Type you won’t be able to assign the proper value to it.
“Mass” is not a Data Type, it’s the name of a variable inside rigidbody and it’s type is float so in order to store mass you would have to declare [SerializeField] float massVariable where float is the type and massVariable is the name. You would only then assign the mass value by getting it from the rigidbody component.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms