- Home /
How to calculate specific data before build and save it?
Hi
I have about 1000 + objects in scene according to the game logic - for each object I need to calculate mesh volume and axial length (max length of 3 lengths) and use later during specific situations in my game
but I'm confused - how to calculate it before build and also see it in inspector?
there is no problem to add script which will calculate volume and max axial lenght once scene is loaded. but in fact this data is not going to be changed, so there is no sence to calculate it each time I run the game. I would like to calculate it before building and save it. but confused how to make it
if I make script which calculate it during play - it will load CPU in vain if I make editor script - it do not save data for build version
Answer by Bunny83 · Sep 22, 2019 at 10:04 AM
this data is not going to be changed, so there is no sence to calculate it each time I run the game
Why not? Producing a lot of data which you could calculate relatively fast at the start just increases your build size. So unless that calculation is extremely complex I would simply let it calculate at the start. This also automatically adapt itself when you add new objects.
Though If you really want to pre-calculate it there are several ways. You probably could create a build preprocessor. Though depending on how and where you store that data you might need to be careful to ensure proper serialization in the assetdatabase.
Another way, assuming you store that data in a ScriptableObject asset in your project, is to write a custom inspector for that object and provide a manual "recalculate" button in the inspector. If the building process of that data is more complex and need configuration you may even create your own dedicated editor window for the precalculation.
Note for heavy in-editor precalculations you may want to have a look at EditorUtility.DisplayCancelableProgressBar, DisplayProgressBar and of course ClearProgressBar to give proper user feedback on the progress.
Your answer
Follow this Question
Related Questions
how to make a level editor in shooting game? 1 Answer
Build problem 1 Answer
I want to save my level progress in my quiz game 1 Answer
Unity Editor not showing my partial class in inspector when i try to assign field() 0 Answers
Editor: How to save changes to a ScriptableObject loaded from Resources? 1 Answer