#It s the same error whenever my raycast
1 messages Ā· Page 1 of 1 (latest)
If you are using the ToonObject more than once it might be betetr to just TryGetComponent once from the first raycast, that way you don't need to try and get it multibel times
Like this? https://gdl.space/tamehemepi.cs
Alright, I tried this but it had the same result as "GetComponent"
As in, the same error
Ok just a sec
Alright.
Something like this maybe
Whatās the difference between what I did and this code?
In your code you still had the TryGetComponent in the if-statement
Oh, I meant between that and this*, sorry
Ohh, I mustāve forgot to remove that. Yeah it says āalready defined within this scopeā and it causes a compiler error anyways.
I donāt think the issue is with the get component anyways, since the āif (input.getbuttondown)ā statement doesnāt return any errors, only the other two statements below it.
The two last if-statements?
No, only the two last if statements that reference āpaintableā
The āif (painted.collider != currentTargetā can be ignored, sorry for the confusion
Ah ok, ill take a look again
Itās fine, it was my bad
Oh its because you try to get it, if you don't get it you still move on to the if statements, ```cs
// Basically this is kinda what is going on
TryGetComponent(out ToonObject paintable) (null)
if (paintable.triggered) (paintable == null)
// If paintable == null from the beginning you cant get anything from them but you still try to get something
Not sure how good of an explanation this is
So, I need to "return" or do something similiar if I don't get it?
Im not sure if this would work, but could be worth a try
if (Physics.Raycast(finder, out painted, range, obstructionMask) && TryGetComponent(out ToonObject paintable))```
painted.transform.TryGetComponent(out ToonObject paintable)
if (paintable == null)
{
return;
}
if (paintable.triggered)
{
}
If that works like I thing it should only run the code if it gets the Toonobject
That would also work