Copying Objects
-
Prerequisite
Introduction
Sometimes we need to add multiple similar objects (shapes, avatars or models). For example, suppose we need to build a forest of many trees. If we add each tree as a new object, it will take a long time to add them, and the program will also run slower due to the increased memory usage.
Instead, we can simply add one tree, then make many copies of it. This will make your program run faster.
Block for Copying An Object
- Share Data: If “Yes”, then the copied object will share the same data as the original object, such as meshes (small faces that compose the object), materials (texture and color) and animation frames; If “No”, then the copied object will have its own materials and no animation.
- New Object Name: The name of the copied object.
Demo 1 - Many Copies That Look the Same
In this example, we need to many trees that look the same, so we can create all of them with share data = Yes.
Here is the program:
Note that right after we make a copy, this copied object becomes the newly selected sprite object. In this example, we are not making 100 copies of the first tree (named “tree 1”). Instead, the second tree is a copy of the first tree, and the third tree is a copy of the second tree, etc.
Demo 2 - Many Copies with Different Colors
In this example, we still want to copy the same gift box many times, but we want to update their materials to different colors. Therefore, we need to select share data = No when we make these copies.
Demo 3 - Many Copies of a Character That Run the Same Animation
Suppose you want to have many pigs that run around in a scene. You can create them with sharing data, so they will all look the same, and run the same animation:
Demo 4 - Unlinked Copies with Different Colors and Animations
In this example, the elephant is copied as not sharing data from the original. As shown, they can have different colors and animations:
-