Forum rules - please read before posting.

Missing Character Prefabs

edited February 2019 in Technical Q&A

Hi,

I have a custom action that takes a Character Prefab in. The problem is that when I drag the character in, AC sometimes loses the reference, but keeps the ConstantID in. When I run the Action in game I get an error: MissingReferenceException: The variable petitioner of QueueUp doesn't exist anymore.

Here's how the Action looks like:

What got me puzzled, is that this works most of the time - I drag the character in, and the Action works as intended, just sometimes it looses the reference to all of the Actions of this type in the ActionList. I can't track down when it exactly happens and only recently became a problem.

AC Version: 1.65.2
Unity: 2018.2.18f1

EDIT:
It seems the reference is lost if I quit the play mode while interacting with the character. Would that be a problem with my custom action?

Comments

  • If it's a custom Action, it's only going to behave how you tell it to. You'll need to post its code.

    You're assigning a character prefab asset file into an ActionList asset file, or a scene-based one?

  • Custom Action basically just grabs the character from parameter and instantiates it in the scene.

    The character is a prefab asset, not scene-based.

    It's not in Resources folder, but I have made a dictionary with all characters and the Action just finds the character through the dictionary reference.

    I'm guessing the reason it can't find the character is because it's not in the Resources folder, but this worked perfectly until now.

  • I did some more testing. The references get lost only if I quit the play mode in the scene where character was instantiated and if he's still there. If I quit the play mode in other scene or if the character is no longer there, then it's all fine (as far as I can tell).

    The ActionList that's responsible for instantiating is an ActionList Asset and it's ran through ActionList in the Scene.

    In other words, the ActionList in scene does ActionList: Run and it runs the ActionList Asset that instantiates the characters.

    And in case it helps to find a solution, the custom Action is just doing this (forget the dictionary stuff I mentioned earlier, I got mixed up and the custom Action here simply instantiated the character from the parameter):

    // Get the character from parameter
    override public void AssignValues()
            {
                petitioner = AssignFile(constantID, petitioner);
            }
    
            // And in Run()
            Quaternion rotation = new Quaternion();
            GameObject spawnedObject = Instantiate(petitioner, markerPos, rotation);
    
  • If the Action is in an asset, and the "petitioner" variable is a prefab, then there's no need to rely on its ConstantID value. That is only necessary when assets / scene objects need to communicate with each other.

    The Object: Add or remove Action can also be used to spawn objects into the scene.

  • Thank you for the reply.

    I've made a custom Action because there's just some extra variables that I need to update when spawning the character (I guess I didn't know about the Object: Add or remove before).

    What I found is that I only lose references if I use ActionList Asset and Prefab Characters.

    I moved the ActionList to scene and it works just fine now. In some cases it would be nice to be able to have ActionList in Asset form and still be able to add a reference to prefab characters though.

  • edited February 2019

    You're re-assigning petitioner with a ConstantID value - which may not always be present.

    What you can try is instead rely on a "runtime" petitione variant this is separate from the one you assign in the GUI, i.e.:

    GameObject runtimePetitioner = null;
    
    // Get the character from parameter
    override public void AssignValues()
    {
        runtimePetitioner = AssignFile(constantID, petitioner);
    }
    
    // And in Run()
    Quaternion rotation = new Quaternion();
    GameObject spawnedObject = Instantiate(runtimePetitioner, markerPos, rotation);
    

    Again, though, if you're only assigning prefabs you do should not need to rely on CID numbers.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.