Easily create custom morphs with MorphService

MorphService

Last year I created a MorphService, but it could be better, so I made better.

The service works by taking a module containing models named as body part limbs (e.g. “Torso”, “Left Arm”, “Lower Right Arm”) and welding parts you put inside the limb model to a character.

In this new version, I lean more on OOP coding styles and apply things I’ve learnt since I made the first one.

How to use the module

Inside the MorphHandler script, simply initialise it as such

local morphService, decorators = require("path to the module")()

The main module returns a tuple containing the service and decorator modules.

Full code example

-- Server script example
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayerService = game:GetService("Players")

local assets = ReplicatedStorage.Assets
local modules = ReplicatedStorage.Modules
local morphs = assets.Morphs

local backpackMorph = morphs.Backpack

-- initialise the MorphService
local morphService, decorators = require(modules.MorphService)()

-- initialise the morph
local myMorph = morphService.new({
	morph = backpackMorph,
	morphType = "Accessory"
})

PlayerService.PlayerAdded:Connect(function(player)
	-- wait for the normal avatar to load fully before applying
	player.CharacterAppearanceLoaded:Connect(function(character)
		
		-- apply the morph
		myMorph:applyMorph({
			character = character,
			decorators = {
				decorators.removeAccessories
			},
			config = {
				overwriteExistingMorphs = true,
				cloneMorphChildren = false
			}
		})
		
	end)
end)

Resulting morph applied to my character

How the module works

The main module returns a function which itself returns a tuple of MorphService, Decorators.
MorphService corresponds with the Service module.
Decorators corresponds with the Decorators module.

Service contains the .new function for initialising a new morph that can be applied to a character.
This the only place where OOP is included.

The Morph type contains a function called applyMorph which can be called after creating a new Morph.

Supporting modules Types and Utility contain all the types that are used and helper functions.

The Decorators module contains the available decorators to do operations on the character to do something specific like removing clothing, accessories and packages. These decorators can be applied based on what your morph needs.

decorators supports any function with the type (character: Model) -> nil.

Morphs can easily be created by copying the given MorphTemplate inside ReplicatedStorage/Assets/Morphs and deleting the limbs you won’t use.

The Reference part within the limb is your guide for where things are positioned on the character. Simply place what you want inside the limb model and place it based on the Reference part.

Once you have made your morph apply it to characters with a script.
See ‘How to use the module’ for using the module in a script.

Resource

MorphService.rbxl (84.5 KB)
All scripts contain documentation

7 Likes

Support R15 Skinned Rthro?
If yes, i would definitely use this cuz i need a good morphing addon.

It works just by checking what the limb models are called. It only has an R6 template, but you would just create an Rthro dummy and do the same as the R6 template.

1 Like

Really appreciate you giving us this resource. Could I be so lazy as to suggest that if you added at least an r15 template (ideally all templates) and some example morphs to try out, I would definitely test it out.

Hey,

I’ve added several templates from Roblox’s rig builder

And I’ve added a helper function to the Utility module which can be used to convert dummies into the correct template.

cc @zoharee4

4 Likes

Thanks a lot for this wonderful community resource!

1 Like

As much as I appreciate the community resource, this does not work. It only works for accessories. Any appearance morphs, this completely does not work. The author assumes for R15 Templates that there is only one child for each specific model (Legs, Arms, etc.), then the morph script itself expects to have more than one children, extremely contradictory and does not make sense.

Please find another resource, don’t waste your time debugging this script.

Hi, thanks for the feedback.

But I’m not sure what you mean by “appearance morphs,” if you could elaborate more I can understand

What do you mean by “only one child” ? The R15 template contains each body part and a reference for where that part is on a character.

1 Like

The R15 Morph Template doesn’t work., the script does an assertion error because the number of children is 1.

The templates don’t contain any morph examples, they’re just there for you to put stuff into. The code rejects a limb that only contains the Reference, which is the error you’re talking about.

Just use the system correctly instead of saying it “completely does not work” :grin:

2 Likes

That’s the problem… Any reference used as a body part cannot use this script for morphing. You are required to have to add accessories or work your way through the system and design something else to avoid the original problem… Custom body parts with meshes? Does not work. That is clearly what I said…

It only works for accessories.

Well yeah that is the point of this module, to put things onto characters. Sorry if “morph” was misleading to refer to custom character models. “Morph” to me, has always just been meshes/parts put onto the character to create uniforms other wearable accessories.

This was clearly just a misunderstanding of what the module is intended for.

1 Like

Hm Ok Tuff moments i guess but., Can i interest you in some: