Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Actions in OnSceneGUI is reset if it is part of a prefab.

Discussion in 'Editor & General Support' started by KitGorn, May 29, 2020.

  1. KitGorn

    KitGorn

    Joined:
    Mar 18, 2018
    Posts:
    1
    Projectile.damageRadius is reset if it is part of a prefab. If you enter a value in the inspector, it is normally saved. Is this a bug or am I doing something wrong?

    Code (CSharp):
    1.  
    2. [RequireComponent(typeof(Rigidbody))]
    3. public class Projectile : MonoBehaviour
    4. {
    5.     [HideInInspector] new public Rigidbody rigidbody;
    6.     public float damageRadius = 1;
    7.  
    8.     void Reset()
    9.     {
    10.         rigidbody = GetComponent<Rigidbody>();
    11.     }
    12. }
    13.  
    Code (CSharp):
    1.  
    2. using UnityEditor;
    3.  
    4. [CustomEditor(typeof(Projectile))]
    5. public class ProjectileEditor : Editor
    6. {
    7.     void OnSceneGUI()
    8.     {
    9.         var projectile = target as Projectile;
    10.         var transform = projectile.transform;
    11.         projectile.damageRadius = Handles.RadiusHandle(
    12.             transform.rotation,
    13.             transform.position,
    14.             projectile.damageRadius);
    15.     }
    16. }
    17.