Forum rules - please read before posting.

Inserting Player Prefab into another object's inspector field

Hi

I have a Player Prefab, and my game allows multiple characters/ character switching. This means if I have an in-scene player object, this is ignored and AC adds my Player from the prefab during runtime.

I want to add my Player into the "Player" field below for an object fading add-on. But this doesn't seem to accept anything except objects that are already in the scene

imageasas" alt="" title="" />

Is there any way to fill this field with my player, after AC adds it into the scene during runtime?

Thanks

Comments

  • You can hook into the OnSetPlayer event to update a field with the Player gameobject at the time they are spawned and set as the Player character:

    using UnityEngine;
    using AC;
    
    public class SetFadeObjectPlayer : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnSetPlayer += SetNewPlayer; }
        private void OnDisable () { EventManager.OnSetPlayer -= SetNewPlayer; }
    
        private void SetNewPlayer (Player player)
        {
            GetComponent <FadeObjects>().player = player.gameObject;
        }
    
    
    }
    
  • Lovely, works perfectly! Thank you so much as always!

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.