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

Method InitCustomNode

Source/Engine/Animations/Graph/AnimGraph.Custom.cpp:159–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159bool AnimGraph::InitCustomNode(Node* node)
160{
161#if USE_CSHARP
162 // Fetch the node logic controller type
163 if (node->Values.Count() < 2 || node->Values[0].Type.Type != ValueType::String)
164 {
165 LOG(Warning, "Invalid custom node data values.");
166 return false;
167 }
168 const StringView typeName(node->Values[0]);
169 const StringAnsi typeNameStd = typeName.ToStringAnsi();
170 MClass* type = Scripting::FindClass(typeNameStd);
171 if (type == nullptr)
172 {
173 LOG(Warning, "Invalid custom node type {0}.", typeName);
174 return false;
175 }
176
177 // Get methods
178 MMethod* load = type->GetMethod("Load", 1);
179 MMethod* evaluate = type->GetMethod("Evaluate", 1);
180 if (load == nullptr)
181 {
182 LOG(Warning, "Invalid custom node type {0}. Missing Load method.", typeName);
183 return false;
184 }
185 if (evaluate == nullptr)
186 {
187 LOG(Warning, "Invalid custom node type {0}. Missing Evaluate method.", typeName);
188 return false;
189 }
190
191 // Initialization can happen on Content Thread so ensure to have runtime attached
192 MCore::Thread::Attach();
193
194 // Allocate managed node object (create GC handle to prevent destruction)
195 MObject* obj = type->CreateInstance();
196 const MGCHandle handleGC = MCore::GCHandle::New(obj);
197
198 // Initialize node
199 InternalInitData initData;
200 initData.Values = MUtils::ToArray(node->Values, MCore::TypeCache::Object);
201 initData.BaseModel = BaseModel.GetManagedInstance();
202 void* params[1];
203 params[0] = &initData;
204 MObject* exception = nullptr;
205 load->Invoke(obj, params, &exception);
206 if (exception)
207 {
208 MCore::GCHandle::Free(handleGC);
209 MException ex(exception);
210 ex.Log(LogType::Warning, TEXT("AnimGraph"));
211 return false;
212 }
213
214 // Cache node data
215 auto& data = node->Data.Custom;
216 data.Evaluate = evaluate;

Callers 1

onNodeLoadedMethod · 0.80

Calls 11

FindClassFunction · 0.85
ToArrayFunction · 0.85
NewFunction · 0.50
FreeFunction · 0.50
CountMethod · 0.45
ToStringAnsiMethod · 0.45
GetMethodMethod · 0.45
CreateInstanceMethod · 0.45
GetManagedInstanceMethod · 0.45
InvokeMethod · 0.45
LogMethod · 0.45

Tested by

no test coverage detected