Creating a Gem in Lumberyard and with gEnv Working

I was going to jump into a tutorial about raycasting in Lumberyard, which uses lots of old cryEngine stuff (like gEnv->pPhysicalWorld) and someone suggested putting a gem wrapper around it; and callable via an EBus.

So that led me to this tutorial. It is super easy to create a Gem, so lets get started.

Creating the Gem

Creating the Gem project is easy with the project configurator (dev\Tools\LmbrSetup\Win\ProjectConfigurator.exe)

tut_create_gem_configurator.gif

The documentation says to go into the gem.json and update some values, but as of 1.10, it seems to have decent defaults. So we can skip this.

Now in the configurator, we need to enable this gem for our project.

tut_create_gem_add_gem

This updated our gem.json file in our project (dev\TutorialSeries\gems.json) to include this new gem. You may think this is enough, but you’d be wrong! (Like I was was 😦 ).

Anyhoo, now we need to add it to our game gem where we put most our code. If you follow my input series, then I have to add it to dev\TutorialSeries\Gem\gem.json as well. Mine now looks like the following:

gem.json

{
    "Dependencies": [
        {
            "Uuid": "352fef7706634c92814c587e84d7165a",
            "VersionConstraints": [
                "~>0.1"
            ],
            "_comment": "CryLegacy"
        },
        {
            "Uuid": "453b88cf44d041709924810814c70a70",
            "VersionConstraints": [
                "~>0.1"
            ],
            "_comment": "PhysicsWrapper"
        }
    ],
    "GemFormatVersion": 3,
    "Uuid": "7a17c44ce76744e1b646e6d8556372c8",
    "Name": "TutorialSeries",
    "DisplayName": "TutorialSeries",
    "Version": "0.1.0",
    "LinkType": "Dynamic",
    "Summary": "A short description of my Game Project Gem. Lol maybe I should fill this out.",
    "Tags": ["Game"],
    "IconPath": "preview.png",
    "IsGameGem": true
}

But What About the gEnv??

So it used to be that when you created a module (and perhaps gem?) you had to do some special stuff to get access to the global environment variable (gEnv). However, since 1.10 (and possibly before – didn’t check) Lumberyard now does this for you.

If you travel to your module.cpp file (mine is PhysicsWrapperModule.cpp), then you will see that our module inherits from CryHooksModule, which sets up the gEnv for us. Woohoo!

Conclusion

Creating gems is pretty easy. We can communicate to our new gem through the EBus system. Any new EBus, be sure to put into the Code\Include folder (like the default one), as our other code will be using it as its include headers.

Take advantage of the system components, and don’t be shy about adding more. To add more, you need to register them in the module.cpp file; just be sure to copy the default one which is already registered for you.

For an example on how to use the new gem for something useful, check out my next tutorial on raycasting.

Written By Greg Horvay

One thought on “Creating a Gem in Lumberyard and with gEnv Working

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s