MagicItem's Bug?

filod

Member
Bug 1:

1637729026478.png

MagicItem.cs:648

I add this line, because Linecast may return false when nothing stands in the way, but i still need `DetermineCastValues` to return true to use item. Is this a bug or i missuse MagicItem's Target Direction?

Bug 2:

Why CastActions serialization broken all the time (in Prefab Variants)?

1637730291352.png
Edit mode.
1637730306906.png
then play mode, i lost two actions forever. (it also happens when i switch prefab mode).
similary issue found here: https://www.opsive.com/forum/index.php?threads/bug-in-magic-item-script.3027/



btw, Are there more design documents/notes on MagicItem/MeleeWeapon/UsableItem/Use etc.. i found myself often hard to understand these in general, and the video& document is far too rudimentary, vague and uncomplete.
for example, i want to cast 3 fireball separately (during an animation), should i design this to a coutinous use type magicitem or else? Why cast delay is not working? etc..
 
Last edited:
I add this line, because Linecast may return false when nothing stands in the way, but i still need `DetermineCastValues` to return true to use item. Is this a bug or i missuse MagicItem's Target Direction?
If the linecast doesn't hit the target then the magic item shouldn't be used. If you want to always want it to fire you should use Forward.

Why CastActions serialization broken all the time (in Prefab Variants)?
I just tried this again and wasn't able to reproduce it. Are you getting any errors?

btw, Are there more design documents/notes on MagicItem/MeleeWeapon/UsableItem/Use etc.. i found myself often hard to understand these in general, and the video& document is far too rudimentary, vague and uncomplete.
for example, i want to cast 3 fireball separately (during an animation), should i design this to a coutinous use type magicitem or else? Why cast delay is not working? etc..
There is a magic item video which gives a good overview of the system. With that said, it's hard to cover all of the specific scenarios so for that situation the best is to just try it out once you have an understanding of the overall concepts. For three fire balls you should add three cast actions during the animation. The trick with the delay is that it must still occur while the magic item is being used. If it is after the use events are complete then it will never trigger.
 
If the linecast doesn't hit the target then the magic item shouldn't be used. If you want to always want it to fire you should use Forward
Even if A standing right in front of B, LineCast can still get false result ( consider A and B are on same plane, linecast from both's feet), the detection may have room to improve.

I just tried this again and wasn't able to reproduce it. Are you getting any errors?
no other errors (except same one in https://www.opsive.com/forum/index.php?threads/bug-in-magic-item-script.3027/#post-14921)
 
The trick with the delay is that it must still occur while the magic item is being used

ok, after some dig, i found another bug that cause me struggling so long.

1637745506638.png

the bug is that, in inspector, when i choose CastUseType.Single, m_ContinuousCast doesn't get reset to false, so m_Used will be true after my first CastAction...
 

Attachments

  • 1637744379891.png
    1637744379891.png
    19.5 KB · Views: 1
  • 1637744417198.png
    1637744417198.png
    49 KB · Views: 1
Even if A standing right in front of B, LineCast can still get false result ( consider A and B are on same plane, linecast from both's feet), the detection may have room to improve.
I will add in the option to use the PivotOffset component which will help in cases like this.

Code:
                    Vector3 position;
                    PivotOffset pivotOffset;
                    if ((pivotOffset = m_TargetColliders[i].transform.gameObject.GetCachedComponent<PivotOffset>()) != null) {
                        position = m_TargetColliders[i].transform.TransformPoint(pivotOffset.Offset);
                    } else {
                        position = m_TargetColliders[i].transform.position;
                    }
                    if (Physics.Linecast(m_CharacterTransform.position, position, out var raycastHit, m_CharacterLayerManager.IgnoreInvisibleCharacterWaterLayers, QueryTriggerInteraction.Ignore)) {
                        var raycastTransform = raycastHit.collider.transform;
                        if (raycastTransform.IsChildOf(m_TargetColliders[i].transform) || raycastTransform.IsChildOf(m_CharacterTransform)) {
                            hitTransform = true;
                        }
                    }

Does this occur for you in a fresh project as well? What version of Unity are you using?
the bug is that, in inspector, when i choose CastUseType.Single, m_ContinuousCast doesn't get reset to false, so m_Used will be true after my first CastAction...
Thanks for tracking that down. I'll reset m_ContinuousCast when the use type changes.
 
Is that when you select the original magic item prefab while in play mode? So if you don't select the original prefab and instead select the prefab instance it works?
 
Is that when you select the original magic item prefab while in play mode? So if you don't select the original prefab and instead select the prefab instance it works?
exactly, try not to select original prefab is my workaround.
 
Thanks, to fix that error you can change the following on line 306 of MagicItem:

Code:
                    if (Application.isPlaying) {
To:

Code:
                    if (Application.isPlaying && m_Character != null) {
 
Top