Version: Unity 6.3 LTS (6000.3)
LanguageEnglish
  • C#

RequiredMemberAttribute

class in UnityEngine.Scripting

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

When a type is marked, all of its members with [RequiredMember] are marked.

using System;
using UnityEngine;
using UnityEngine.Scripting;

public class NewBehaviourScript : MonoBehaviour { void Start() { new PlayerProfile(); } }

class PlayerProfile { // Will survive managed code stripping because PlayerProfile is used [RequiredMember] public int level;

// Will survive managed code stripping because PlayerProfile is used [RequiredMember] public void ResetProgress() { }

// The property, property getter method, and property setter method will survive managed code stripping because PlayerProfile is used [RequiredMember] public int Score { get; set; }

// The property and property getter method will survive managed code stripping because PlayerProfile is used public int HighScore { [RequiredMember] get; set; }

// The property and property setter method will survive managed code stripping because PlayerProfile is used public int Coins { get; [RequiredMember] set; }

// The event, the add method, and the remove method will survive managed code stripping because PlayerProfile is used [RequiredMember] public event EventHandler ProgressChanged;

// Might not survive managed code stripping: without [RequiredMember], this member // is kept only if the linker detects that it's used. Mark it to guarantee it survives, // for example when it's only accessed through reflection or serialization. public int sessionCount; }

class LegacyPlayerProfile { // Will not survive stripping because LegacyPlayerProfile is not used [RequiredMember] public int level;

// Will not survive stripping because LegacyPlayerProfile is not used [RequiredMember] public void ResetProgress() { }

// Will not survive stripping because LegacyPlayerProfile is not used [RequiredMember] public int Score { get; set; }

// Will not survive stripping because LegacyPlayerProfile is not used [RequiredMember] public event EventHandler ProgressChanged;

// Will not survive stripping either. This member has no [RequiredMember], but that // makes no difference: once LegacyPlayerProfile itself is stripped, all of its members go with it. public int sessionCount; }