#(obviously :P) Now, I don't know how
1 messages ยท Page 1 of 1 (latest)
the actual inserting stuff is as follows, it works like this for the non-vehicle storage
{
if(!storage)
{
Print("no storage");
return;
}
if(!storageManager && !vehStorageManager)
{
Print("no manager");
return;
}
if (!Replication.IsServer())
return;
if(amountAdded < amountToAdd)
{
if(storageManager)
{
for(int x = 0; x < amountToAdd ; x++)
{
ZEL_TierData spawn = chosenItem();
ResourceName m_Resource = "{E8F00BF730225B00}Prefabs/Weapons/Grenades/Grenade_M67.et";
//spawn.m_sPrefab;
Print(m_Resource);
amountAdded ++;
Print(amountAdded);
Print(storageManager.TrySpawnPrefabToStorage(m_Resource));
Print("Inserting to storage");
bool result = storageManager.TrySpawnPrefabToStorage(m_Resource);
PrintString(m_Resource + " stored?:" + result);
}
}
the function runs in EOnInit
storageManager =//= Vech storageManager
sorry, that's a bit of old code I didn't update yet..
storageManager = ScriptedInventoryStorageManagerComponent.Cast(owner.FindComponent(ScriptedInventoryStorageManagerComponent));
this returns whatever the storage manager type is on the entity, so is universal.
I have a print on init that shows it found the vehicle manager:
ScriptedInventoryStorageManagerComponent storageManager = SCR_VehicleInventoryStorageManagerComponent<0x0000023B484F2C30>
Except thats not how it works ๐
well I was told it does, as ScriptedInventoryStorageManagerComponent is the parent class of the other managers ๐
the same code also didn't work when I exclusively found the veh manager
Parent yes, but child has new stuff - hence childs
but it finds the vehicle storage component ๐ค
Swap it out, or cast it down. Minimize your potential for errors.
Finding it sure, but I dunno if it "acts" like it - it should act like the parent
Children casted to the parent, just has "less features" and runs the parents code, but retain the size and contents, just it become 'unaccessable'.
will revert my code back, i changed to that to avoid bloating with checking for if it's vehicle or standard
Yea, you'll have to do a "Does this cast work?" - I'm a vech. elseif "Does this one work?" - I'm everything else
yeah I had it casting first to inv storage manager, then if that wasn't found cast to veh inv manager
Fixed now?
still tweaking, will let you know
rgr. Meth is bad ๐
nope still nothing 
refactored code:
{
if(!storage)
{
Print("no storage");
return;
}
if(storageManager == null && vehStorageManager == null)
{
Print("no manager");
return;
}
if (!Replication.IsServer())
return;
if(amountAdded < amountToAdd)
{
if(vehStorageManager != null)
{
for(int x = 0; x < amountToAdd ; x++)
{
ZEL_TierData spawn = chosenItem();
ResourceName m_Resource = "{E8F00BF730225B00}Prefabs/Weapons/Grenades/Grenade_M67.et";
//spawn.m_sPrefab;
Print(m_Resource);
amountAdded ++;
Print(amountAdded);
Print(vehStorageManager.TrySpawnPrefabToStorage(m_Resource));
Print("Inserting to vehicle");
bool result = vehStorageManager.TrySpawnPrefabToStorage(m_Resource);
PrintString(m_Resource + " stored?:" + result);
}
}
}
}```
Just FYI this would inject twice.
i have no idea why your veh storage works and mine doesn't, code wise they seem pretty much the same apart from I'm doing it on the owner, maybe too quickly?
oh how come?
But that aside, this code is being run and comes back true?
vehStorageManager.TrySpawnPrefabToStorage(m_Resource) is a action, and you have it in a print
ah gotcha, didn't realise print would actually run it
I mean, how does it get the value then? ๐
well yeah I just didn't think it actioned it fully, assume it would jut "fake" it for debug or something :p but yeah it returns true looking at the prints
SCRIPT : int amountAdded = 1
SCRIPT : 1
SCRIPT : Inserting to vehicle
SCRIPT : string s = '{E8F00BF730225B00}Prefabs/Weapons/Grenades/Grenade_M67.et stored?:true'``
vehStorageManager is the correct one and casted like mine?
should be, that's run on init via:
Print(storageManager);
if(storageManager == null)
{
vehStorageManager = SCR_VehicleInventoryStorageManagerComponent.Cast(owner.FindComponent(SCR_VehicleInventoryStorageManagerComponent));
Print(vehStorageManager);
}```
the prints suggest it works:
SCRIPT : SCR_InventoryStorageManagerComponent storageManager = NULL SCRIPT : SCR_VehicleInventoryStorageManagerComponent vehStorageManager = SCR_VehicleInventoryStorageManagerComponent<0x0000023A616DB470>
and owner must be a vech, or it would fail so thats all good. aside from that ifstatement logic, but this is scratch code, so we will overlook it ๐
And owner is getting set via oninit you said, of what the comp?
is it worth adding a short delay to the insertToStorage() function? It's called at the end of EOnInit but could it still be too slow?
Yeah it's on a custom comp on the vehicle entity itself
and you meaning because I used == null instead of !storagemanager? ๐
Na the if statement if not container, just assumes vech, which can also fail
ahh I guess, but I only intend for this comp to be used with either/or of those so shouldn't
The delay wouldn't matter, if comps wouldn't exist it would fail
So an attached comp should grab the proper owner, and this "add" code is being triggered right at start?
yep, comp is attached to a vehicle (or object in the other case) that isn't spawned, then on that vehicle being spawned it runs the "add" stuff
it works completely fine just not on a vehicle for some reason
Maybe try a delay. Maybe it lies, and says everything is fine, but its to early. Doubtful, but I can't see off hand what the issue is. The code is 2 lines, and it is succeeding.
when you hit tab and look at the trunk, nothing there?
and its a non custom vech, aside from your comp?
yup, just the basic ural + cargo open aside from my comp + changes to the inventory capacity stuff and removing a faction affiliation component
it was the delay
added a 50ms call later and grenades are there
Its likely the faction comp. I just deleted it and it broke my code.
Things rely on things and when debugging, same things need to say same, beause its the changes/differences is why it doesn't work ๐
but at least the delay is a work around I guess ๐
well that's weird then, because adding the delay worked for me rather than inserting during the oninit...
I'll see if I can do the same
why would inv need a faction comp? It doesn't for boxes, seems like an odd requirement for vehicles
but yeah the delay has worked for me for whatever reason
Well you could walk thought the code, but VechManager is not UniManager - its not same code, the same reason your parent problem
rather annoying how simple a thing that was in the end, I've spent so long trying to figure out why it didn't work. I'm 90% sure i tried with a faction comp before and it was the same outcome but maybe I'm mistaken
it also doesn't make sense why the delay would work if it needed a faction comp 
Weird. Mine is totally broken now ๐ - so maybe its not that. Could be the "breaking of the prefab" but shouldn't be
Just tested it. So breaking the prefab breaks the system. Very odd, must have some underlying attachment code.
The delay made no impact on pre-break, and no weapons showed post delay break.
I'll double check faction, just for learning.
Neat. So without the faction + delay it works. I suspect your problem is you broke the prefab to remove the faction and this has a "feature" that makes the default code unhappy
So just to wrap this up, it looks like it's the breaking of the prefab. The delay didn't make any difference on my end. But of course I can't test two perfectly, because I have to break the prefab to get rid of the faction. I changed it to another class, disabled it and set it to none - and that still passed.
Anyways. These are the worst kind of features. At least we figured it out eventually and you can move on and do what you got to do.
yeah sounds like a lot of random fuckery that makes no real indication as to what broke or why delay fixed it ๐ just enfusion things I guess (or a bug in the system), thanks for taking the time to troubleshoot though and i guess something to keep in mind in future haha
As the old adage goes. Embrace the suck ๐
0 reason to down cast.
ScriptedInventoryStorageManagerComponent InvManComp = ScriptedInventoryStorageManagerComponent.Cast(owner.FindComponent(ScriptedInventoryStorageManagerComponent));
Find component gets the component of that type, regardless of what is is further down the hierarchy
FindComponent(ScriptedInventoryStorageManagerComponent)
will return a SCR_VehicleInventoryStorageManagerComponent or a SCR_InventoryStorageManagerComponent
depending on what youi're callin it on