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

Method Clone

Source/Engine/Level/Actor.cpp:2100–2141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2098}
2099
2100Actor* Actor::Clone()
2101{
2102 // Collect actors to clone
2103 auto actors = ActorsCache::ActorsListCache.Get();
2104 actors->Add(this);
2105 SceneQuery::GetAllActors(this, *actors);
2106
2107 // Serialize objects
2108 MemoryWriteStream stream;
2109 if (ToBytes(*actors, stream))
2110 return nullptr;
2111
2112 // Remap object ids into a new ones
2113 auto modifier = Cache::ISerializeModifier.Get();
2114 for (const Actor* actor : *actors.Value)
2115 {
2116 if (!actor)
2117 continue;
2118 modifier->IdsMapping.Add(actor->GetID(), Guid::New());
2119 for (const Script* script : actor->Scripts)
2120 {
2121 if (script)
2122 modifier->IdsMapping.Add(script->GetID(), Guid::New());
2123 }
2124 }
2125 if (HasPrefabLink() && HasParent() && !IsPrefabRoot())
2126 {
2127 // When cloning actor that is part of prefab (but not as whole), ignore the prefab hierarchy
2128 Actor* parent = GetParent();
2129 do
2130 {
2131 modifier->IdsMapping.Add(parent->GetPrefabObjectID(), Guid::Empty);
2132 parent = parent->GetParent();
2133 } while (parent && !parent->IsPrefabRoot());
2134 }
2135
2136 // Deserialize objects
2137 Array<Actor*> output;
2138 if (FromBytes(ToSpan(stream), output, modifier.Value) || output.IsEmpty())
2139 return nullptr;
2140 return output[0];
2141}
2142
2143void Actor::SetPhysicsScene(PhysicsScene* scene)
2144{

Callers

nothing calls this directly

Calls 10

HasParentFunction · 0.85
GetIDMethod · 0.80
IsPrefabRootMethod · 0.80
GetParentFunction · 0.70
NewFunction · 0.50
ToSpanFunction · 0.50
GetMethod · 0.45
AddMethod · 0.45
GetParentMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected