| 194 | } |
| 195 | |
| 196 | void Actor::OnDeleteObject() |
| 197 | { |
| 198 | // Check if actor is still in game (eg. user deletes actor object via Object.Delete) |
| 199 | if (IsDuringPlay()) |
| 200 | { |
| 201 | // Check if parent is still during game (eg. user removes child actor but rest is still in game) |
| 202 | const bool isParentInPlay = _parent && _parent->IsDuringPlay(); |
| 203 | if (isParentInPlay) |
| 204 | { |
| 205 | // Call event on object removed from the game (only from th top object, don't call it for children of the tree) |
| 206 | Level::callActorEvent(Level::ActorEventType::OnActorDeleted, this, nullptr); |
| 207 | } |
| 208 | |
| 209 | // Note: endPlay will remove managed instance |
| 210 | EndPlay(); |
| 211 | |
| 212 | if (isParentInPlay) |
| 213 | { |
| 214 | // Unlink from the parent |
| 215 | _parent->Children.RemoveKeepOrder(this); |
| 216 | _parent->_isHierarchyDirty = true; |
| 217 | _parent = nullptr; |
| 218 | _scene = nullptr; |
| 219 | } |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | if (_isEnabled) |
| 224 | OnDisable(); |
| 225 | if (_parent) |
| 226 | { |
| 227 | // Unlink from the parent |
| 228 | _parent->Children.RemoveKeepOrder(this); |
| 229 | _parent->_isHierarchyDirty = true; |
| 230 | _parent = nullptr; |
| 231 | _scene = nullptr; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // Fire event |
| 236 | Deleted(this); |
| 237 | |
| 238 | // Delete children |
| 239 | #if BUILD_DEBUG |
| 240 | int32 callsCheck = Children.Count(); |
| 241 | #endif |
| 242 | for (int32 i = 0; i < Children.Count(); i++) |
| 243 | { |
| 244 | auto e = Children.Get()[i]; |
| 245 | ASSERT(e->_parent == this); |
| 246 | e->_parent = nullptr; |
| 247 | e->DeleteObject(); |
| 248 | } |
| 249 | #if BUILD_DEBUG |
| 250 | ASSERT(callsCheck == Children.Count()); |
| 251 | #endif |
| 252 | Children.Clear(); |
| 253 |
nothing calls this directly
no test coverage detected