Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
1
Question by Blankzz · Aug 14, 2011 at 03:42 PM · functioncompilecall

Call function after script compilation?

Is there a way to call a function after Unity compiles the scripts. I would like to check if an object exists in the scene and if it isn't add it. I think its possible if I call the function from another GameObject in scene but I would like to avoid that if possible. I don't think it's possible but thought I would ask in case I am missing something.

Comment
Add comment · Show 5
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 Waz · Aug 14, 2011 at 03:44 PM 0
Share

I have an answer to your title, but I don't see how the title matches the question. Compilation of what?

avatar image Blankzz · Aug 14, 2011 at 03:48 PM 0
Share

Each time scripts are compiled. I just thought Unity doesn't always compile all the scripts so I would probably either have to force compilation somehow.

avatar image Waz · Aug 14, 2011 at 03:54 PM 0
Share

Unity compiles scripts whenever they change. I don't understand how this could relate to adding an object to the scene whenever a script changes though. I wrote a really crude "Shell Window", and since there is no eval, the user's command needs to be compiled in order to execute it.

avatar image Blankzz · Aug 14, 2011 at 04:10 PM 0
Share

Sorry I don't see how it doesn't relate. Say if I'm creating an API for release and certain gameobjects are needed in the scene for it to function correctly, the user would have to know what objects to add to the scene before hand add them manually. I want to resolve this problem by adding them automatically. I thought the best time would be after the scripts are compiled.

avatar image Waz · Aug 14, 2011 at 09:37 PM 0
Share

I would suggest that it's up to the developer to signal that they want your functionality by creating those scene objects, not the other way around. Imagine they are building their Loading scene which is just a title and a menu that loads other scenes - why would they want your GameObjects in that scene? Seems to me like your design is wrong. What are you actually trying to build?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Aug 14, 2011 at 05:19 PM

Usually such things are handled via Start or Awake funcs looking for the appropriate objects, issuing a Debug.LogError or you could make it fancier than that. You can detect this in an editor script, but those run at odd times: project load, change in editor script, etc. You could make a menu item like 'Init My System' which does the check on user command.

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
0

Answer by tonytopper · Sep 22, 2021 at 08:07 PM

You can do this using Unity's serialization callbacks.


More specifically, you can implement the ISerializationCallbackReceiver interface and create OnBeforeSerialize and OnAfterSerialize methods.


Understanding Unity's serialization stack can be helpful for all sorts of things so I'd recommend digging into it a little bit.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Call GUITexture and script 1 Answer

Return multiple parameter 3 Answers

Variable inside a function's NAME - does it work? 2 Answers

RPC call failed 1 Answer

{ ERROR } call a function from other script 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