Forum begins after the advertisement:
[Part 9] Feedback: unpause, audio, random bug
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 9] Feedback: unpause, audio, random bug
- This topic has 4 replies, 3 voices, and was last updated 7 months ago by Joseph Tang.
-
AuthorPosts
-
March 5, 2024 at 2:03 am #13463Allan ValinParticipant::
Hey,
The unpause method wasn’t working, but the solution was in a previous forum post.
Some AudioSource details aren’t mentioned or repeated every time in the video:
– main menu: not mentioned to add the audio mixer to the audio source (it works without, but I assume if you change the volume it won’t be affected)
– pause menu: adding audio source isn’t at all mentioned (or at least shown)
– player audio: finally mentioned to add the audio mixer, which prompted me to go to the two previous sections to solve the problems.I wasn’t sure if I had to add the DestroyInMainMenu script to ALL prefabs, but I did it anyway. It says to add to the Singleton prefabs. Are there ones that aren’t singletons? idk
Sometimes when I used Desolate Dive the ground collision isn’t detected, I tried recording it, but after 2 minutes trying the bug decided to disappear lol kinda randomly appears.
Back to my previous being damaged when attacking problem:
At 22:40 (part 9) code I saw that the code shown is different from what is shown on the video where the code is shown.
Basicallyif (hasTakenDamage) return;
isn’t there and the method name is different as well.public virtual void EnemyHit(float _damageDone, Vector2 _hitDirection, float _hitForce) { if (hasTakenDamage) return; health -= _damageDone; if (!isRecoiling) { GameObject _orangeBlood = Instantiate(orangeBlood, transform.position, Quaternion.identity); Destroy(_orangeBlood, 5.5f); rb.velocity = _hitForce * recoilFactor * _hitDirection; } hasTakenDamage = true; }
Since that a code that is different from what was given and seems to work differently, I wonder if it could be the culprit. Which is supposed to be the “real” version?
All in all, aside from a couple fast forwards making things difficult to understand what was done, part 9 was one of the easiest videos to follow.
March 6, 2024 at 6:48 pm #13466TerenceKeymaster::Thanks for posting this Allan. I’ve pinned this topic so that we can review this while working on the revamp. Also gave you another Bug Reporter + Content Contributor badge as thanks for your help in typing this out.
Regarding the
EnemyHit()
function, can you show me what the other code is? I’ll have a read and give you my thoughts on it.March 8, 2024 at 7:08 am #13492Allan ValinParticipant::Inside
Enemy
the variableprotected bool hasTakenDamage = false;
is already initialized, but changing that doesn’t seems to make a difference.
In both cases, I tried jumping over an enemy while hitting another on the right, that causes the DownAttackTransform to freeze the player on the air taking damage multiple times in a row.While before the code wasn’t showing any errors, after changing hasTakenDamage between not having a starting value and returning it to the having one, now I can see two of them.
NullReferenceException: Object reference not set to an instance of an object UnityEditor.Graphs.Edge.WakeUp () (at <84411d99c4a04a5f824cb9590142af8d>:0) UnityEditor.Graphs.Graph.DoWakeUpEdges (System.Collections.Generic.List
1[T] inEdges, System.Collections.Generic.List
1[T] ok, System.Collections.Generic.List` 1[T] error, System.Boolean inEdgesUsedToBeValid) (at <84411d99c4a04a5f824cb9590142af8d>:0) UnityEditor.Graphs.Graph.WakeUpEdges (System.Boolean clearSlotEdges) (at <84411d99c4a04a5f824cb9590142af8d>:0) UnityEditor.Graphs.Graph.WakeUp (System.Boolean force) (at <84411d99c4a04a5f824cb9590142af8d>:0) UnityEditor.Graphs.Graph.WakeUp () (at <84411d99c4a04a5f824cb9590142af8d>:0) UnityEditor.Graphs.Graph.OnEnable () (at <84411d99c4a04a5f824cb9590142af8d>:0)ArgumentNullException: Value cannot be null. Parameter name: _unity_self UnityEditor.SerializedObject.FindProperty (System.String propertyPath) (at <9920ff0c944845d7b9f9a61ef1478edc>:0) UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindPropertyRelative (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedProperty parentProperty) (at <8c3449848bd845499081ddbe4a09b367>:0) UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <8c3449848bd845499081ddbe4a09b367>:0) UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.ContinueBinding (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <8c3449848bd845499081ddbe4a09b367>:0) UnityEditor.UIElements.Bindings.DefaultSerializedObjectBindingImplementation+BindingRequest.Bind (UnityEngine.UIElements.VisualElement element) (at <8c3449848bd845499081ddbe4a09b367>:0) UnityEngine.UIElements.VisualTreeBindingsUpdater.Update () (at <7c69dfc1e63a4ea388c73014d3c7ce20>:0) UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <7c69dfc1e63a4ea388c73014d3c7ce20>:0) UnityEngine.UIElements.Panel.UpdateBindings () (at <7c69dfc1e63a4ea388c73014d3c7ce20>:0) UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <7c69dfc1e63a4ea388c73014d3c7ce20>:0) UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <7c69dfc1e63a4ea388c73014d3c7ce20>:0) UnityEditor.RetainedMode.UpdateSchedulers () (at <8c3449848bd845499081ddbe4a09b367>:0)
Here are all the times I found a mention of
EnemyHit()
.PlayerController
void Hit(Transform _attackTransform, Vector2 _attackArea, ref bool _recoilBool, Vector2 _recoilDir, float _recoilStrength) { Collider2D[] objectsToHit = Physics2D.OverlapBoxAll(_attackTransform.position, _attackArea, 0, attackableLayer); if (objectsToHit.Length > 0) { _recoilBool = true; } for (int i = 0; i < objectsToHit.Length; i++) { if (objectsToHit[i].GetComponent<Enemy>() != null) { objectsToHit[i].GetComponent<Enemy>().EnemyHit(damage, _recoilDir, _recoilStrength); if (objectsToHit[i].CompareTag("Enemy")) { Mana += manaGain; } } } private void OnTriggerEnter2D(Collider2D _other) //for up and down cast spell { if (_other.GetComponent<Enemy>() != null && pState.casting) { _other.GetComponent<Enemy>().EnemyHit(spellDamage, (_other.transform.position - transform.position).normalized, -recoilYSpeed); } }
Enemy
public virtual void EnemyHit(float _damageDone, Vector2 _hitDirection, float _hitForce) { if (hasTakenDamage) return; health -= _damageDone; if (!isRecoiling) { audioSource.PlayOneShot(hurtSound); GameObject _orangeBlood = Instantiate(orangeBlood, transform.position, Quaternion.identity); Destroy(_orangeBlood, 5.5f); rb.velocity = _hitForce * recoilFactor * _hitDirection; } hasTakenDamage = true; }
Bat
public override void EnemyHit(float _damageDone, Vector2 _hitDirection, float _hitForce) { base.EnemyHit(_damageDone, _hitDirection, _hitForce); if (health > 0) ChangeState(EnemyStates.Bat_Stunned); else ChangeState(EnemyStates.Bat_Death); }
Fireball
private void OnTriggerEnter2D(Collider2D _other) { if (_other.tag == "Enemy") { _other.GetComponent<Enemy>().EnemyHit(damage, (_other.transform.position - transform.position).normalized, -hitForce); } }
I also noticed that my enemies didn’t have an Anim animator assigned to them, so I just added the same that was below them in the Inspector. Didn’t seem to change anything.
March 8, 2024 at 11:59 pm #13500TerenceKeymaster::To answer this question of yours:
Since that a code that is different from what was given and seems to work differently, I wonder if it could be the culprit. Which is supposed to be the “real” version?
I suspect the
if(hasTakenDamage) return;
line is there to prevent an enemy from taking more than 1 instance of damage in a single frame. This can happen if the enemy has multiple colliders, and your attack collider overlaps with at least 1 of them. It is a “cheap” way of doing this — the better (but harder) way will be to build your combat system in such a way that it circumvents this error entirely.That being said. Keeping this there would be a better choice than leaving it out.
March 31, 2024 at 12:43 pm #13652Joseph TangModerator::It’s a bit late, but to add on,
thehasTakenDamage
is likely a bugfix as mentioned for an issue presented during the series’ creation.Thus, it’s likely the creators had integrated this fix without mentioning it.
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: