C# is working with objects, there is no direct memory control. In C++ you can work with memory as you want, but this feature gives you many problems, such as 0xc0000005 (read/write access violation). In C# we can give no (blotch) about getting references or instances, e.g.: in Unity3d we can find an object using
GameObject choppa = GameObject.Find("MahChoppa") as GameObject;
There we will get only a reference of Mah Choppa, not an instance. If i left types the same, but make it as it must look like in C++ it will be like this:
GameObject * choppa = Cast<GameObject>(GameObject::Find("MahChoppa"));
There variable choppa is ADDRESS, where founded object contains and we sure, that after that address we have type GameObject. That’s what star means. Double colon after GameObject means that we trying to access something static (function, method or variable). As i know, in Unity GameObject.Find still returns an Object, so let’s imagine, that C++ version returning “void*” - just an address, no type. So we use Cast to make sure, that what we found is legal to use as this type (we can directly convert it into GameObject*, but who knows, maybe it isn’t that type we want). If Cast fails, it returns nullptr or just zero, there we can understand, that it isn’t what we wanted.
Now why I wrote this: using all info you given, there can be a few things that might be the problem:
->That trick with UWorld is insanely cool, i should say, but it will cause the crash. You mustn’t use instance of UWorld, world is huge container, it isn’t good idea. If you need reference to world you need to write this:
UWorld * world = GetWorld();
And you don’t need “this” also, you aready in “this” namespace.
->Trace function don’t need FHitResult and “actor” in arguments. You can locally create FHitResult and then return it. Like this:
FHitResult f;
...
GetWorld()->LineTraceSingleByChannel (f, start, end, ECC_WorldStatic, CombatCollisionQuery);
return f;
->Are you sure you need ATrace class in so hard way? I really don’t know how fast GetDefaultObject is, but probably better save pointer once, instead of getting it many times. And what is “t” actually… This combination looks strange, but i hope it will work.