Forum rules - please read before posting.

Change material on Player?

I feel like the answer to this is probably really obvious, so I feel a bit like an idiot for posting it, but is it possible to change materials on child objects of Player prefabs?

Player prefabs are loaded into the scene, so I can't define which object I want to switch the material on in an Action List, right? If you don't assign "Change material" an object that already exists in the scene, it results in a NullReference exception.

Not that that would help, because prefabs' child objects are inaccessible from the defining window, so if I wanted to change a material of an object that wasn't the root object of the prefab, I'd be stuck.

Anyway, is there a workaround for this that I'm not seeing?

Thanks,
— Lurky.

Comments

  • The Player doesn't necessarily need to be spawned when the game begins - if you need to, you can still have it present in the scene file so that you can reference it with scene-based Actions.

    However, you can still affect the prefab by using ActionList assets, instead of scene-based prefabs:

    -Create a new ActionList asset and give it the Object: Change material Action
    -Drag the Player prefab into the scene
    -Assign the Player's child object (from the scene) into the Action's field
    -A Constant ID number will be auto-generated on the object, and displayed in the Action
    -Find the Constant ID component on the child object, and check Retain in prefab?
    -Click Apply on the Player's scene object to update the prefab, and remove it from the scene

    The asset will refer to the player's child via the Constant ID number, which will persist among all scenes, instead of the actual object reference.
  • Works beautifully!
    Thanks a lot, Chris!

    — Lurky.
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.