페이지

2023년 7월 5일 수요일

When are All GameObject Awake(), OnEnable(), Start() called?

 1.

ExLifeCycle script is attached into All GameObjects (ex: Parent, Child1, ... )



public class ExLifeCycle : MonoBehaviour
{
private void Awake()
{
Debug.Log($"{name}:Awake");
}

private void OnEnable()
{
Debug.Log($"{name}:OnEnable");
}
void Start()
{
Debug.Log($"{name}:Start");
}
}


When Playing, the follow logs comes
----------------------
Child1:Awake
Child1:OnEnable
SubChild(1):Awake
SubChild(1):OnEnable
Child1(3):Awake
Child1(3):OnEnable
Parent:Awake
Parent:OnEnable
Child1(2):Awake
Child1(2):OnEnable
.....
Child1:Start
SubChild(1):Start
...


the calling order of GameObject Awake,Enable is not fixed, and random.
and After All gameObject OnEnable() are called, Start() of all are called.


2.


when playing unity in this case, 

SubChild:Awake
SubChild:OnEnable
Child1(2):Awake
Child1(2):OnEnable
SubChild:Start
Child1(2):Start

are not printed in console.
.






2023년 5월 5일 금요일

Unity Apple PlugIn Build Error ( .. has no meta file, but it's in an immutable folder .. )

 apple unity plugin

the upper build guide doesn't have the information correctly.


Before typing this python command,

python3 build.py

Make sure that you have Unity 2020.3.33f1 version.


IF not,

When you build your app by Unity iOS,

the following error will occur.


Asset Packages/com.apple.unityplugin.core/Plugins/iOS has no meta file, but it's in an immutable folder. The asset will be ignored.



https://developer.apple.com/forums/thread/710437


2022년 10월 29일 토요일

Unity Animation Rigging : ChainIK Constraints

3d 툴로 체인 object들을 만들고 각 object 들의 origin 은 anchor 역할을 하는 끝마디에 위치시켜놓는다. ( 별도로 bone 을 만들필요없다.)


unity 에서 3d 툴로 작업한 chain object들을 가져와서, 아래 그림과 같이 hierarchy 구조로 GameObject 들을 설정한다. 

그런다음 UnityAnimationRigging RigSetup, Blender Render Setup 을 설정한다. 

Rig1 아래 빈 GameObject 를 생성하여 ChainIKConstraint 를 추가한다. 설정은 아래 2번째 이미지를 참고하라.

Unity를 실행시키고, ChainIkConstraint 에서 설정한 target 을 움직이면, Chain이 그것을 향해 꼬리를 친다.




Unity Animation Rigging : Two Bone IK Constraint

아래 그림과 같이

 RootLeg, MidLeg, Ankle, Foot GameObject들이 부모 자식관계로 구성되어 있다. 이 상태로 Unity Animation Rigging 의 Rig Setup, Bone Render Setup 한다. 

( 3d툴에서 bone을 만들필요없다. )

여기서 중요한 포인트는

각 GameObject의 origin이 회전축 anchor 로 위치해 있어야 한다는 것이다. (아래 그림에서 RootLeg의 origin 위치를 참고하라)

이는 Blender 툴에서 orgin을  별도 설정해야 한다. 















1. Two Bone IK Constraint Setup

Left Leg, Right Leg 을 담당할  LL, RL GameObject 들을 생성하고 그곳에 각각 Two Bone IK Constraint 을 추가한다. 

설정값은 아래 그림을 참고 한다. 

(tip을 먼저 설정하고 Auto Setup from tip Transform 메뉴를 선택하면 자동으로 LL_target, LL_hint GameObject들이 자식으로 추가된다.)




2. IK Foot Solver setup 
















IKFootSolver 소스는 Unity Animation Rigging 에는 없고,  Unity Animation Rigging Sample
에 있다. 

1) target

이 소스의 역할은 두 발을  LL_target, RL_target 에 위치시키기 위한 것이다. 
IK Foot Solver.Body (Hip) 가 앞으로 이동하면, Hip 의 중심이 바뀌면서, 특정 step 을 벗어나면, LL_target, RL_target이 앞으로 하나씩 이동하게 한다. 
결론적으로 발이 그 이동된 target으로 옮겨지게 된다.

처음  LL_target, RL_target의 위치는 정확히 두 발이 내딪는 위치에 놓아야 한다. 

2) hint

LL_hint, RL_hint 의 위치는 다리의 접혀지는 위치에 굽어지는 방향으로 놓아야 한다. 예를 들어 사람의 다리면 무릅의 앞쪽에 놓아야 사람다리처럼 구부리고, 새 다리라면 관절이 뒷쪽에 놓아야 새다리처럼 뒤로 굽혀진다. 

* 문제는 현재 사람의 다리로 하면, 다리자체가 움직이면서 180 도 회전하는 현상이 있는데. 이유를 모르겠다.


아래 그림들 참고










2022년 9월 12일 월요일

C# LINQ Group by Count

 

Car[] cars = new[]
{
new Car(1, "one"), new Car(2, "two"), new Car(3, "three"), new Car(4, "four"), new Car(5, "five"), new Car(6, "six")
, new Car(3, "three 2"), new Car(4, "four"), new Car(5, "five")
, new Car(3, "three"), new Car(4, "four")
, new Car(3, "three 2")
};

var q = from a in cars group a by new
{
a.id, a.name
} into g
select (g.Key.id , g.Key.name, count: g.Count()) ;
foreach (var a in q)
{
if (a.count >= 2)
{
Console.WriteLine(a);
}

}

output

(3, three, 2)
(4, four, 3)
(5, five, 2)
(3, three 2, 2)

2022년 4월 8일 금요일

On ParticleSystem Stretched Billboard Render Mode, Particle not Showing

When ParticleSystem.mainModule.StartSpeed = 0,

Particle are not showing.

Stretched Billboard : Particle stretched in the direction of motion.

this means particle must have speed.





camera scale : Particle stretched in the camera velocity

speed scale: Particle stretched in the speed of particle ( mainModule.startSpeed )

Length scale: Particle stretched in the length scale