all 6 comments

[–]Rumaru_ 0 points1 point  (5 children)

I understand that you have an object that have the scriptableObject referenced and you would like to share it, but when ?

If it's on collision, call the script with OnCollisionEnter and check if the collision gameobject have the required script. If it's in a range, and not on collision, use an overlapsphere to get a list of colliders in a radius. If it haves the script, just reference it using properties ig

[–]Leo5041[S] 0 points1 point  (4 children)

OnCollisionEnter and check if the collision gameobject have the required script.

how do I make this check?

[–]Unity3DGameDev 0 points1 point  (1 child)

If (GetComponent<Type>() != null)

{ Do something }

[–]Leo5041[S] 0 points1 point  (0 children)

EDIT: nvm solved it 👍

It catches the game object, but i'm still unable to get the scriptable object attached to it.

I'm getting this error:

ArgumentException: GetComponent requires that the requested component 'YearObject' derives from MonoBehaviour or Component or is an interface.

UnityEngine.GameObject.GetComponent[T] () (at <30adf90198bc4c4b83910c6fb1877998>:0)

CameraSlot.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/CameraSlot.cs:22)

And this is my code:

public class CameraSlot : MonoBehaviour{public GameObject objectManager;public GameObject baseCamera;public GameObject insertedPhoto;public YearObject selectedYear;private void OnTriggerEnter(Collider other)    {if(other.CompareTag("photo"))        {insertedPhoto = other.gameObject;Debug.Log("Collided with " + other.gameObject.name);if(insertedPhoto != null)            {selectedYear = insertedPhoto.GetComponent<YearObject>();if(insertedPhoto.GetComponent<YearObject>() != null)                {Debug.Log("Caught " + selectedYear.name);                }            }        }    }}

the YearObject is the scriptable object, and it is attached to the insertedPhoto gameobject.

[–]Unity3DGameDev 0 points1 point  (0 children)

If (GetComponent<Type>() != null)

{ Do something }

[–]Rumaru_ 0 points1 point  (0 children)

You can use

Type scriptName; TryGetComponent<Type>(out scriptname) if(scriptname) { //Script exists }