Scriptable Objects - can't select a reference

I’m having a weird issue using Scriptable Objects.

I have a public reference to a Scriptable Object in my code. Sometimes I can select it and sometimes I can’t.

I was, at first able, to select an SO. I ran the game and everything worked fine. Then I exited Unity and reopened the project and I couldn’t select an SO. If I click on the SO it just doesn’t show up in the editor. Also dragging the SO doesn’t work either. I’m new to SOs so I could be doing something wrong.

Also it if I force Unity to recompile the code below (which is the code that I’m trying to plug the SO into), it will work. But it will only work until I close and reopen Unity then it won’t let me access the SO again.

This is a screenshot of me trying to select it but after selecting it, it doesn’t show up in the editor.
Imgur

using System;
using UnityEngine;
using PathologicalGames;

using System.Collections;

namespace tchrisbaker {
    [CreateAssetMenu(menuName = "CastSpell/ProjectileSpell")]
    public class ProjectileSpell : CastSpellSO {
      
        public ParticleBehavior particleBehaviorSOInstance;
        private Transform Projectile;
        public Transform prefab;        
        public float projectileLifeTime = 3.5f;

        public override IEnumerator Cast(GameObject Target, string poolName, Transform spawnLoc, GameObject shooter)
        {
            Projectile = PoolManager.Pools[poolName].Spawn(prefab, spawnLoc.position, Quaternion.identity);
            PoolManager.Pools[poolName].Despawn(Projectile, projectileLifeTime);

            Projectile.gameObject.GetComponent<ParticleImpactScript>().shooter = shooter;

            return particleBehaviorSOInstance.MoveProjectile(Projectile, Target.transform);
          
        }       
    }
}

I just realized that I’m doing all this on a prefab. Is that the reason?

Sounds like a weird bug. You should be able to reference a SO on a prefab.

This question may seem silly, but is the SO file alone (no other classes are in it?) and it’s named the same as its class?

Any error messages? Can you drag-and-drop the SO into the slot?

If it shows up in the list of assignable things, it should be possible to assign. The only thing I can think of that you might’ve done to prevent assignment is to have a custom editor that messes up serialization somehow.

@Baste No, there were no errors in the logs.

@methos5k , now that you bring it up, I remember renaming the file at one point and then changing the class name to the same name and maybe that caused some kind of bug.

So I created all of the classes involved from scratch again and it seems to be working.

Thanks everyone.

Interesting. :slight_smile: I wouldn’t have thought that would cause a bug lol. I meant literally if they were different now.
Or inside a file/other script; I had that once, and it made the SO work, but not all was good. :slight_smile:

In any event, glad you got it fixed half by accident. good stuff :wink:

1 Like