Search Issue Tracker
By Design
Votes
0
Found in
2017.1.0b8
Issue ID
920425
Regression
Yes
Warning appears when changing MeshFilter.sharedMesh during OnValidate()
Reproduction steps:
1. Open project attached (TerrainEngine.zip).
2. Open scene "testscene".
3. Select object "Terrain".
4. Change UTerrain script parameters, for example size.
Expected result: Once size is changed OnValidate function will work fine.
Actual result: Error appears: "SendMessage cannot be called during Awake, CheckConsistency, or OnValidate"
Note: There is a code that is called during OnValidate:
Mesh terrainMesh = new Mesh();
meshFilter.sharedMesh = terrainMesh;
Reproduced on: 2017.1.0a2, 2017.1.0b9, 2017.2.0a3.
Works fine on: 5.5.0f3, 5.6.1f1, 5.6.1p4.
Regression introduced in 2017.1.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Articulation Body with 'Revolute' Joint Type has erratic behavior when Upper Limit is set to above 360
- WebGL Player fails to render Scene when Terrain with Detail Mesh is added and WebGPU Graphics API is used
- Inconsistent errors are logged when different types are passed into the Query "Q<>" method in UIToolkit and the ancestor VisualElement is null
- Crash on GetMaterialPropertyByIndex when opening a specific Scene
- Discrepancies in the styling are present when using a TSS file instead of a USS file in custom EditorWindow
PoyrazGoksel
Jul 21, 2022 21:20
I was working on a project that has been developed by another developer which was using your asset. That was a clever move to add the issuetracker link to comment.
Here I`ve corrected it. OnValidate is not designed to be used like that. Your there are many other design flaws and performance issues in the code so beware. Sadly I don`t have time to fix them. However if you are interested you can reach me: poyraz_goksel@hotmail.com
private bool isValidatedInScene;
public virtual void OnValidate()
{
// OnValidate can get called before awake in editor, so make sure the required things are initialized
if( rnd == null ) rnd = GetComponent<MeshRenderer>(); // Needed for ApplyProperties
if( mf == null ) mf = GetComponent<MeshFilter>(); // Needed for UpdateMesh
ShapeClampRanges();
UpdateAllMaterialProperties();
ApplyProperties();
if (isValidatedInScene == false)
{
EditorSceneManager.sceneOpened += OnSceneOpened;
}
// if( MeshUpdateMode == MeshUpdateMode.SelfGenerated )
// meshOutOfDate = true; // we can't update the mesh in OnValidate because of https://issuetracker.unity3d.com/issues/warning-appears-when-changing-meshfilter-dot-sharedmesh-during-onvalidate
// UpdateMesh( force:true ); gosh I wish I could do this it would solve so many problems but Unity has some WEIRD quirks here
isValidatedInScene = true;
}
private void OnSceneOpened(Scene scene, OpenSceneMode mode)
{
EditorSceneManager.sceneOpened -= OnSceneOpened;
UpdateMesh(true);
}
shubhamswaraj2021
Aug 18, 2020 16:29
good one <a href="https://www.lyricsauto.com">lyricsauto</a>
sravani-sga
Aug 01, 2018 10:22
Works without any problem with Unity 5.6.X
Warning with 2017.4.5f1
When this issue will get resolved
Will this effect the performance of game?
Juicy-Beast
May 09, 2018 14:39
"By Design" the error message is misleading
clckwrk
Jan 08, 2018 21:27
Why is this "By Design"?
The warning message has nothing to do with what is causing it. If this really is caused by editing sharedMesh, then the wording of the warning should reflect that.
stephero
Sep 12, 2017 06:41
Same problem if I try to change Layer from OnValidate:
void OnValidate () { gameObject.layer = LayerMask.NameToLayer("Water"); }
Works without any problem with Unity 5.6.X
Warning with 2017.1.0f3 and 2017.1.1f1
Flavelius
Aug 31, 2017 09:39
I just encountered this. Why is it by design, when SendMessage is not even used (in code)?
GDesmoulins
Aug 18, 2017 09:26
Same problem for me for a simple SetActive on a child (always on a "OnValidate" command)
Kiyoshi-Fujita
Jul 16, 2017 04:39
Just by the user operating the Inspector, just creating a new game object with a script from the OnValidate () call will produce a yellow error.
SendMessage cannot be called during Awake, CheckConsistency, or OnValidate