Reduce the size of a prefab

Hi guys

Hope you’re doing well !
Sorry about this post, unfortunatelly google is not enought powerfull to help me to the last part :frowning:

(it’s my first time i use script Unity)

I’ve downloaded an obsolete plug-in for a game and updated it.
It take me all the night cause I’ve to learnt and understand how the engine work.
Unity look like amazing.

The aim was to spawn a prefab (backpack) and put on the back to the player.

var pack = GameManager.server.CreateEntity(".... new_pack.prefab", player.transform.position + new Vector3(0, 0.15F, -0.80F), Quaternion.Euler(0, -90,90));
  1. Replace the good prefab - Done
  2. Put on the back - Done (thx to Vector3)
  3. Use the good rotate - Done (thx to Quaternion)
  4. Use the good size - Fail (maybe with .localScale but it’s not clear for me) the backpack is to big :hushed:

Anyone could help me with that ?

Have a good day
Matthieu

Yes, this is how you set the local scale. It is relative to the parent of the object, or if at the root, it is absolute.

Try:

pack.transform.localScale = Vector3.one * 0.1f;

This will make it 0.1 of original size.

(Ninja edit to fix my typo… 0.1 is supposed to be 0.1f … sorry!)

2 Likes

Thanks a lot for your reply @Kurt-Dekker !

I’ve try to this way

            public void SpawnEntVisual(BasePlayer player)
            {
                if (visualEntity != null || !Configuration.ShowOnBack)
                    return;

                var pack = GameManager.server.CreateEntity(".... new_pack.prefab", player.transform.position + new Vector3(0, 0.15F, -0.80F), Quaternion.Euler(0, -90,90));
                pack.transform.localScale = Vector3.one * 0.1;
                pack.SetParent(player);

                pack.UpdateNetworkGroup();
                pack.SendNetworkUpdateImmediate();

                pack.Spawn();

Unfortunately i’ve this error message:

So i’v try with “new Vector” or other type o functions founded on the net but nothing works.
I’ve to pute this into the same void isn’t it ?

Thanks

Oop, sorry, my typo: the 0.1 is supposed to be 0.1f. I edited the original reply above.

1 Like

Hi @Kurt-Dekker

Many thanks for your time !
Unfortunately it doesn’t work.

I’ve try with other syntaxes and way, but it’s the same.
I think your function is correct but don"t why it doesn’t work into the environement.
Btw i’ve to do without resizing.

            public void SpawnEntVisual(BasePlayer player)
            {
                if (visualEntity != null || !Configuration.ShowOnBack)
                    return;
                var pack = GameManager.server.CreateEntity(".... new_pack.prefab", player.transform.position + new Vector3(0, 0.15F, -0.80F), Quaternion.Euler(0, -90,90));
                pack.transform.localScale = Vector3.one * 0.5f;
                pack.SetParent(player);
                pack.UpdateNetworkGroup();
                pack.SendNetworkUpdateImmediate();
                pack.Spawn();

Best
Matthieu

Run your game until the point where the backpack is in place.

Press PAUSE at the top center of Unity editor.

Go into the scene, find the backpack.

Select the Scale Tool from the upper left.

Adjust the size of it to suit.

Look in the inspect. Write down the values for scale.

Put those into your prefab.

OR… assign them as a new Vector3() object.

Oh thanks, but as mentioned the game is not mine.
I’m working on an obsolete plug-in.
I can change the .cs and reload the plugin in order to see what happen in game.
(i couln’t open the game with the editor)
Thx for your time.

Have a good day.
Matthieu.

Hey,

localScale works using the parent; you are setting the localScale before setting the parent,
therefore, you have a scale related to the world

Have fun,
Sylafrs.

Edit: I don’t know the errors that you’ve got.
You are saying that you can’t open the editor, how do you change the script of the game?
if I don’t know that, I can’t help you, the error may be there.

If you have some plugins make sure that they are not missing any dependencies.
If you’re using a DLL make sure all the DLLs it needs are also included.

1 Like

Hi @Sylafrs

Many thanks for your reply.
Context: i’m runing a GameServer with the legacy game and more a plug-in who is be able to load some files .cs in order to apply some mods to the game.
I’ve downloaded this .cs but it was totally obsolete.
I’ve made the changes into the .cs and reload the file into the gameserver.
It had take a time to find the good values for the Quaternion.Euler(0, -90,90)) (a lot of … reload…)

For now all is working find, and players enjoy this new feature.
The only issue is the size of the backpack.

I’ve don’t see any parent class into the .cs, maybe i’ve to create one no ?
According to: Unity - Scripting API: Transform.parent

Best
Matthieu

By parent, I meant hierarchical parent (see Transform objects as nodes of trees), when the parent is set to null, the object is attached to the world and is the root of its own tree.
It’s not about class legacy :slight_smile:
(each GameObject has a Transform component)

When a GameObject has its transform component attached to another gameObject’s transform component, the transform component ‘inherits’ the position, rotation and scale of its parent

If B is attached to A ( <=> B’s parent is A)
If A world position is (0, 0, 1)
If B local position is (1, 0, 0)
If A local scale is (1, 1, 1)
If A local rotation is Quaternion.identity (i.e. no rotation),

Then B world position will be (1, 0, 1)

[edit: was confused between A and B at a moment, corrected it ^^]

The best to understand transform behaviour is to test the transform tools in the editor.
If you can’t open your project, just play a little with unity on a new blank project, it will help you.
You can also watch this video:

1 Like

Thanks a lot @Sylafrs

I’m on it !

Best
Matthieu