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

Method Spawn

Source/Engine/Level/SceneObjectsFactory.cpp:126–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126SceneObject* SceneObjectsFactory::Spawn(Context& context, const ISerializable::DeserializeStream& stream)
127{
128 // Get object id
129 Guid id = JsonTools::GetGuid(stream, "ID");
130 ISerializeModifier* modifier = context.GetModifier();
131 modifier->IdsMapping.TryGet(id, id);
132 if (!id.IsValid())
133 {
134 LOG(Warning, "Invalid object id.");
135 return nullptr;
136 }
137 SceneObject* obj = nullptr;
138
139 // Check for prefab instance
140 Guid prefabObjectId;
141 if (JsonTools::GetGuidIfValid(prefabObjectId, stream, "PrefabObjectID"))
142 {
143 // Get prefab asset id
144 const Guid prefabId = JsonTools::GetGuid(stream, "PrefabID");
145 if (!prefabId.IsValid())
146 {
147 LOG(Warning, "Invalid prefab id.");
148 return nullptr;
149 }
150
151 // Load prefab
152 auto prefab = Content::LoadAsync<Prefab>(prefabId);
153 if (prefab == nullptr)
154 {
155 LOG(Warning, "Missing prefab {0}.", prefabId);
156 return nullptr;
157 }
158 if (prefab->WaitForLoaded())
159 {
160 LOG(Warning, "Failed to load prefab {0}.", prefab->ToString());
161 return nullptr;
162 }
163
164 // Get prefab object data from the prefab
165 const ISerializable::DeserializeStream* prefabData;
166 if (!prefab->ObjectsDataCache.TryGet(prefabObjectId, prefabData))
167 {
168 LOG(Warning, "Missing object {1} data in prefab {0}.", prefab->ToString(), prefabObjectId);
169 return nullptr;
170 }
171
172 // Map prefab object ID to the deserialized instance ID
173 modifier->IdsMapping[prefabObjectId] = id;
174
175 // Create prefab instance (recursive prefab loading to support nested prefabs)
176 obj = Spawn(context, *prefabData);
177 }
178 else
179 {
180 const auto typeNameMember = stream.FindMember("TypeName");
181 if (typeNameMember != stream.MemberEnd())
182 {
183 if (!typeNameMember->value.IsString())

Callers 1

CreateActorMethod · 0.45

Calls 15

GetGuidFunction · 0.85
FindScriptingTypeFunction · 0.85
GetModifierMethod · 0.80
WaitForLoadedMethod · 0.80
FindMemberMethod · 0.80
MemberEndMethod · 0.80
GetIntMethod · 0.80
SpawnFunction · 0.50
StringClass · 0.50
TryGetMethod · 0.45
IsValidMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected