Properly Troubleshooting "Accessed None" Error with Dynamic Material when a delay fix the issue

Hey fellow Unreal Engine enthusiasts,

I’ve been working on a project that involves using a Widget to display the weapon ammo through a Dynamic Material. However, I’ve encountered a persistent issue with the “Accessed None” error during initialization (Begin Play), and I’m seeking some guidance on finding a cleaner and more reliable solution.

Here’s the problem:

Scenario:

  • I have a “Set Weapon Material” function that configures the dynamic material to the Widget during Begin Play.
  • Initially, connecting the “Set Weapon Material” directly to Begin Play causes the “Accessed None” error for the dynamic material.

image

Temporary Solution:

  • To resolve this, I’ve resorted to adding a “Delay Until Next Tick” node before the “Set Weapon Material” function, which seems to allow the asset to be referenced correctly.

New Issue:

  • As my game has expanded, the “Accessed None” error has resurfaced.
  • The only workaround I’ve found is to add more “Delay Until Next Tick” nodes, which doesn’t feel like a reliable long-term solution. I don’t want to keep stacking delays as my project grows.

Attempts Made:

  • I’ve tried using the “Async Load Asset” node, but without success.

Has anyone encountered a similar issue and found a cleaner, more dependable way to ensure assets load properly during initialization? I’d greatly appreciate any insights or alternative approaches to tackle this problem.

Thanks in advance for your help!

1 Like

What’s in ‘set weapon material’?

I mean, where are you waiting for the material to be valid? ( maybe you can show the area of code that’s giving you ‘none’ )

If you know it’s going to be ok, you can use a delay with a loopback, waiting for it

Here is what’s inside, nothing complex:

I’ll do as you suggested, I thought there was a better way of making sure a reference was loaded.

Would you see any situation where this “infinite loop” could fail?

1 Like

I don’t think there is.

The only way it could fail is if the material never loads. Then you’ve got a problem anyway.

If you’re paranoid about it running forever ( I don’t think it would have much impact ), you can always exit the loop and give up after a certain number of tries :slight_smile:

The base of the issue is the pawn is spawned some milliseconds after the controller. This why delays on begin play work as a hack.

You need to poll your references before initializing them.

Level loads gamemode, gamemode gets controller and spawns the pawn. It then executes possession. Controller → pawn

Wait until all is spawned, then reference.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.