[1.0.4] Sharing Dynamic objects with multiple plugins - ntoxin66/Dynamic GitHub Wiki

Dynamic can share its instances between plugins without you having to write natives. Dynamic does this by allowing plugins to name their objects so third-party plugins can find them based on their name.

Dynamic dynamic = Dynamic();
dynamic.SetName("MyPlugin_Name");

You can see that we name this Dynamic object "MyPlugin_Name". As multiple plugins can potentially use the same name, it's recommended that you prefix your plugins name to the start of each object name you define. This will avoid your plugin from overwriting any pointers that use the same name within other plugins.

To find Dynamic objects, we make use of a static Dynamic.FindByName() method. We parse the name of object we are looking for as a param. If a pointer isn't found for the specified object name, INVALID_DYNAMIC_OBJECT is returned. The best way to check the return is valid is to check the dynamic.IsValid property.

Dynamic dynamic = Dynamic.FindByName("MyPlugin_Name");
if (!dynamic.IsValid)
{
	// Throw some type of error or do nothing
	return;
}

Dynamic makes use of a StringMap to reference object names to their respective pointers. This means the lookup is incredibly fast and you shouldn't be worried about storing too many object name pointers for performance reasons.

It's still recommended to only store object names where absolutely necessary. Dynamic does support static setting objects for your server and player settings. You should attempt to store your references in these static objects before reverting to naming your own objects to keep the internal StringMap's as clean as possible.