MUID vs sourceTemplateId

I am still a bit confused about when to use MUID vs sourceTemplateId. If someone can help explain which is best to use in which situations.

  1. MUID
    In what situations should I use MUID?

  2. sourceTemplateId
    In what situations should I use sourceTemplateId?

Common Cases:

  1. Persistent Storage Of Equipment
    The equipment is a template. I would like to save which equipment the player owns in persistent storage. Which value should I save in persistent storage: MUID vs sourceTemplateId? The goal is to load the value from persistent storage, and spawn the template for the player.

  2. Spawning Templates
    If I want to spawn a template in a game, which should I use: MUID vs sourceTemplateId?

  3. Cloning Games
    Let's say I clone game A (which uses MUIDs), and call it game B. Since MUIDs are only guaranteed to be unique with a given game, does this mean that in game B, the MUIDs are no longer valid in game B. In other words, if I try spawning something in game B using an MUID, it may fail since the MUID was only valid in game A.

To clarify, sourceTemplateId is a MUID. When an object exists as part of a template that was spawned or placed in the world, the sourceTemplateId property will be populated with the MUID of the template definition it came from.

As far as your use cases go:

  1. For persistent storage, you shouldn't use MUIDs at all. If you decide at some point to change one of your pieces of equipment, you may end up changing the MUID for that item, and then you'll have storage data using an invalid MUID. You'll want to create a table that maps your own unique equipment identifiers to the MUIDs of their respective equipment templates, and then use your identifiers in persistent storage.

  2. When spawning a template, ideally you'll have a custom property of type Asset Reference defined on a script somewhere, and you'll use that to spawn the template. Using Asset References instead of hard-coding MUIDs will improve the sharability of your scripts and templates, should you decide to publish any of them in Community Content. It also improves functionality if you want to copy and paste components between your own games. sourceTemplateId can still be useful here, if you have a template that has already been spawned and want to spawn a new copy of it in response to some event. (Say a mesh has moved into a trigger and you want to duplicate it, you can look at sourceTemplateId to see which template to spawn a copy of.)

  3. At the moment that you clone a game, the MUIDs should all be identical, so you'll be fine there. But following best practices with using Asset Reference custom properties will help you avoid any problems that could pop up.

1 Like

Listen mister! Don't you come in here dropping excellent answers while I'm typing mine. I even had screenshots! :stuck_out_tongue:



1 Like