Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 felixpk · Aug 08, 2014 at 06:29 PM · monobehaviourdatastore

Is there a "Lightweight Monobehaviour"?

Hey there,

Problem: I have an Transform array of chairs, each one can be empty or occupied.

I think extending Monobehaviour would be a little overhead.

So is there a way to attach a script to a GameObject that is not extending Monobehaviour (or ScriptableObject).

And is ScriptableObject a choise for such a problem?

Edit: I just noticed that when I add a "ScriptableObject-Script" to one chair, you are not allowed to add it to another chair, so this way it would not work either.

Thanks in advance!

Comment
Add comment · Show 2
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 robertbu · Aug 08, 2014 at 07:09 PM 3
Share

I don't know what the overhead is for a component, but I don't think it can add much to your app (compared to say one bitmap) unless you have a huge number of chairs. If the only place the boolean is accessed is from the array, then create an array of structs containing one transform and one boolean.

avatar image tanoshimi · Aug 08, 2014 at 07:18 PM 2
Share

From memory of the results of some tests I did a while ago, if you do create a huge number of $$anonymous$$onoB's and don't need Start() or Update(), make sure you delete them from the template file. Having empty function definitions seemed to add a slight overhead for each one, but otherwise I agree with @robertbu - I think you might be unnecessarily pre-optimising here.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Owen-Reynolds · Aug 08, 2014 at 07:14 PM

I don't think extending MonoB is that big a deal. I assume you mean you need a small data script:

 class chairData : MonoBehaivoir {
   public bool Occupied;
 }

I think the engine merely adds all of your Updates, OnCollisionEnters .... to a list. I don't think that every frame it loops through every chair object, looking for a nonexistant Update.

But if you really want it lightweight, just don't put the class on the object. If you have 20 chairs, store the list of 20 occupied vars in an array, elsewhere:

 // some "master" script, which can also hold chair data:
 class playerScript : MonoB {

   class chairData {
     public Transform chairT;
     public bool Occupied;
   }

   chairData_t[] Chairs;
 ...

At start, fill the Chairs array with a pointer to each actual chair. The drawback is there's no good way to go from a real chair back to this. Like, if someone clicks on a chair, have to loop through the array, checking Chairs[i].chairT==clickedOnChair. But that's not really a problem.

I've found I usually want to add OnCollision or some other MonoBehaiv function, or set Inspector vars by hand. So I usually end up rewriting these as MonoB scripts, anyway.

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 felixpk · Aug 08, 2014 at 07:23 PM 0
Share

Thank you! So I will end up with every chair having a script that stores it's current status. When the overall opinion is that this will not cause noticeable overhead, then this is a solid solution. Thanks again.

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

22 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

Related Questions

Using a non-monobehaviour class file 1 Answer

Script as a variable being assigned later in script??? 3 Answers

Reading data from one script to another 0 Answers

How to save data on iOS? 1 Answer

Best practice to store levels and highscores etc 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