MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / SetParent

Method SetParent

Source/Engine/Scripting/Script.cpp:81–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81void Script::SetParent(Actor* value, bool canBreakPrefabLink)
82{
83 // Check if value won't change
84 if (_parent == value)
85 return;
86 if (IsDuringPlay() && !IsInMainThread())
87 {
88 LOG(Error, "Editing scene hierarchy is only allowed on a main thread.");
89 return;
90 }
91
92 // Unlink from the old one
93 if (_parent)
94 {
95 if (!value && _parent->IsDuringPlay() && _parent->IsActiveInHierarchy() && GetEnabled() && _wasEnableCalled)
96 {
97 // Call disable when script is removed from actor (new actor is null)
98 Disable();
99 }
100
101 _parent->Scripts.RemoveKeepOrder(this);
102 }
103
104 // Set value
105 const auto previous = _parent;
106 _parent = value;
107
108 // Link to the new one
109 if (_parent)
110 {
111 _parent->Scripts.Add(this);
112 }
113
114 // Break prefab link for prefab instance objects
115 if (HasPrefabLink() && IsDuringPlay() && canBreakPrefabLink)
116 {
117 BreakPrefabLink();
118 }
119
120 // Check if actor is already in play but script isn't
121 if (value && value->IsDuringPlay() && !IsDuringPlay())
122 {
123 // Prepare for gameplay
124 Initialize();
125 {
126 SceneBeginData beginData;
127 BeginPlay(&beginData);
128 beginData.OnDone();
129 }
130
131 // Fire events for scripting
132 if (GetEnabled())
133 {
134 Start();
135 Enable();
136 }
137 }
138 else if (!previous && value && value->IsDuringPlay() && value->IsActiveInHierarchy() && GetEnabled())

Callers

nothing calls this directly

Calls 6

IsInMainThreadFunction · 0.85
StartFunction · 0.85
RemoveKeepOrderMethod · 0.80
OnDoneMethod · 0.80
InitializeFunction · 0.50
AddMethod · 0.45

Tested by

no test coverage detected