Open UE4SS opened 9 months ago
Incredibly useful feedback! I appreciate you taking the time to write this up!
I'll be sure to get a PR out to remedy these things soon, I was just about to start on a second pass over the docs. This was my first attempt at a rudimentary doc, and I'm no UE4SS expert, so the corrections and suggestions are super helpful!
These are things I noticed in the Lua modding guide that I think could be improved. Though the delivery of this issue might be dry and boring, please don't see this as a list of demands, this is just me trying to be helpful so obviously ignore or discuss anything you disagree with.
There will be mentions of
GUObjectArray
, and this is, put simply, a giant array that holds every single UObject in the entire game, and that can easily be hundreds of thousands of objects. It's important that you know this definition.There are checkboxes to make it easier for you to keep track of things in case you decide to tackle some of these issues.
[ ] https://pwmodding.wiki/docs/lua-modding/ue4ss-functions#registerhook: It's mentioned that RegisterHook fires the Lua callback after the real UFunction has executed. This is not true. RegisterHook is rather complicated and the following explains how it works: The callback will fire before the UFunction has executed if the UFunction is native (native == non-BP) and otherwise it will fire after. If the UFunction is native, you can also supply a second callback to RegisterHook, and that callback will fire after the UFunction has executed, thus giving a full pre/post callback set-up. There is currently no support for a pre callback if the function isn't native.
[ ] https://pwmodding.wiki/docs/lua-modding/ue4ss-functions#registerhook: In the 'What's up with the :get() ?' section, it mentions the last lesson and I'm unable to find this lesson. I started from https://pwmodding.wiki/docs/lua-modding/lua-intro and kept clicking the button at the bottom to continue.
[ ] https://pwmodding.wiki/docs/lua-modding/ue4ss-functions#registerhook: After the 'What's up with the :get() ?' section, there's a line that looks like it might accidentally be placed outside the section because it doesn't seem to make much sense all on it's own.
[ ] https://pwmodding.wiki/docs/lua-modding/ue4ss-functions: Regarding both RegisterHook and NotifyOnNewObject, it might be worth mentioning that you should try group up as many things in the same hook/notification as possible instead of registering new hooks or notifications for the same function/object. This is to reduce lag and loading times because each hook/notification needs to be processed and that's not free on the ol' CPU, jumping back & forth between C++ and Lua, etc, so it's a good idea to not spam ten NotifyOnNewObject calls for the same object.
[ ] https://pwmodding.wiki/docs/lua-modding/ue4ss-functions#staticfindobject: It might be worth hammering home the importance of caching objects as much as possible here. I've seen people using StaticFindObject for default objects in hooks/notifications without a cache, and generally CDOs don't even need any cache-invalidation logic so caching a CDO should be very easy and definitely worth doing to save a potentially very expensive full GUObjectArray iteration in the middle of a game tick.
[ ] https://pwmodding.wiki/docs/lua-modding/ue4ss-functions#find-functions: I'd really like to hammer home the importance of not using FindFirstOf or FindAllOf in actual production code, they are great for prototyping though. As with, StaticFindObject, they can be very slow, and FindFirstOf, as the name suggests, only gives you the first instance it finds, regardless if that's not the one you were looking for, because who knows, maybe the game spawned a new instance and hasn't yet killed the last once. The FindAllOf function, doesn't have the same problem because as the name suggests it finds all instances of the class and gives them to you, which is very useful and because of that, it's more likely that people will try to use it in actual production code and that comes at a super heavy cost as it's always guaranteed to iterate the entirety of GUObjectArray for every invocation of the function.
[ ] https://pwmodding.wiki/docs/lua-modding/ue4ss-functions#find-functions: There is no mention of what makes these functions different than StaticFindObject, FindObject, and FindObjects. The difference is that FindFirstOf/FindAllOf can only give you instances, while the other three can give you any kind of object in GUObjectArray.
[ ] https://pwmodding.wiki/docs/lua-modding/ue4ss-functions#loopasync-and-executewithdelay: It might be worth changing 'every_so_often' to 'every_x_ms' just to make it as clear as possible how to use the function.