I am finding that binding of properties and methods is not doing what I would have thought when using inherited classes with virtual/overridden methods/properties. Given the classes below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
usingUnityEngine;
namespaceAssets.NodeCanvasTests
{
publicclassTestBase1:MonoBehaviour
{
publicvirtualstringmyName
{
get
{
return"TestBase1";
}
}
publicstringclassName
{
get
{
returnthis.GetType().FullName;
}
}
}
}
namespaceAssets.NodeCanvasTests
{
publicclassTestChild1:TestBase1
{
publicoverridestringmyName
{
get
{
return"TestChild1";
}
}
publicstringmyRealName
{
get
{
returnmyName;
}
}
}
}
When binding to TestChild1.myName and using a LogText (or even a LogVariable) action node, the value ‘TestBase1’ is logged rather than the expected ‘TestChild1’. Similar behavior when calling a method – the base’s method is called and not the overridden one.
Is there something I need to do to get the overridden method/property called? Or is this a problem with NodeCanvas implementation?
Attached is a sample scene that demonstrates this issue.
Hello and sorry for the late reply due to summer vacation.
This is a unintended behavior that I wasn’t aware of. Thanks for reporting this problem.
To fix this quickly, please open up ReflectionTools.cs file, fine and replace method RTCreateDelegate with the following code:
The difference here is that if re-fetch the method type from the true type of the instance if any before creating the delegate and as such, the delegate will correctly call the child method/property from there-on.
Please let me know if making this change also works for you.