Destroy(gameObject);

Today, I learned about Destroy(gameObject)
Destroy isn’t ran immediately, but at the end of the frame.
I was testing the below code and noticed that the stump and treeTop would spawn twice instead of a single time. Turns out that when my Player hits the Tree via Collider detection, the Collider would hit the gameObject twice before the Destroy takes place.

I read there’s another option of using Destroy Immediate, but absolutely not recommended (many posts on the why’s if you google it)

I had a few quick fixes on the table, but ultimately decided to shorten the Player hit collider’s enabled time from 0.5f to 0.2f.

[Rpc(SendTo.Everyone)]
private void SpawnVisualsClientRpc(float randomYRotation)
{
	// Destroy the original tree
	Destroy(gameObject);

	// Spawn stump
	var stump = Instantiate(treeStumpPrefab, transform.position, transform.rotation);
	stump.transform.localScale = transform.localScale;
	Destroy(stump, 5f);

	// Spawn top
	var treeTop = Instantiate(treeTopPrefab, transform.position,
		Quaternion.Euler(0f, randomYRotation, 0f));
	treeTop.transform.localScale = transform.localScale;
	Destroy(treeTop, 5f);
}

Diving into Netcode for GameObjects

Reading all these posts about “Starting with Multiplayer compatibility is crucial to your game if you ever plan on having multiplayer”, was enough to get me started on testing out Netcode for GameObjects.
My recent practice project I started will be called “DevSlice”.

The goal of this project is to have mini implementations of game features.
Ideally having a scalable and decoupled code for reusability in my future “commercial” projects (if any). A verticle slice. Not too spend much time on art, although I totally get the projects are more fun with they nice on the eyes too.

Third day of testing netcode, a lot of reading, and asking Claude for help, I now understand that coding a multiplayer game is way more challenging.
Not just challenging, but time consuming, and having to be aware of each logic more thoroughly than a Single player only project. I am sure coding will become smoother once you get in the workflow.

Chopping trees, spawning resoureces

Today I tested how to simulate chopping a tree down, and spawn resources with a random rotation, random count.
Also noticed with the default behavior, the Player was hitting the spawned cut down tree and resoureces.
I learned how to create a dedicated layer for collisions to mask specified layers.

Had a rough time with Unity’s Avatar Masks

After successfully importing a few animation along with my proto typing Blueberry looking character, I quickly realized that I had to read up on Avatar Masks.

When the character is walking and attack animation is triggered, the walk freezes. Basically making the character look like it’s sliding for a brief moment.
After looking up forum posts and youtube videos, most of the information were on Avatar Masks using Humanoid Avatar type.
My Blueberry is using a Generic avatar. This meant that I have to manually select which bones to mask from the Transform menu within the Avatar Mask’s inspector/property.
My bones are generated using Blender’s Rigify and I haven’t looked deep into the bone relations. This gave me a hefty 6 hour troubleshooting session thinking I had something wrong elsewhere…

TLDR; I missed a few bones that were related to the upperbody animation which I had to have selected.